0

Magento2 move header compare link after custom block in the header

I have added custom block in header as follows

<referenceContainer name="header.topcontent">
            <block class="Magento\Cms\Block\Block" name="Blockname" after="-">
                <arguments>
                    <argument name="home_page_top_content_block" xsi:type="string">home_page_top_content_block</argument>
                </arguments>
            </block>
        </referenceContainer>

I need to display this block catalog.compare.link after my custom block

0
<move element="catalog.compare.link" destination="page.wrapper" before="main.content"/>

Might help someone

0

you have to override default.xml in your theme.

app/design/frontend/{{YOUR THEME NAME HERE}}/default/Magento_Theme/layout/default.xml

We have created one example of how to move compare link after custom block.

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="page.top">
            <block class="Magento\Cms\Block\Block" name="blockname" after="-">
                <arguments>
                    <argument name="block_id" xsi:type="string">home_page_top_content_block</argument>
                </arguments>
            </block>
        </referenceContainer>
    </body>
    <move element="catalog.compare.link" destination="page.top" before="home_page_top_content_block"/>
</page>

After that add the below CSS in your custom CSS or less.

.page-wrapper .item.link.compare .no-display {
    display: block;
}

Please check and let us know if you still facing any issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.