Question

I am working on a Magento 2.1.7 shop. To achieve this, I have created a child-theme of Magento Blank.

My top links (above the logo) are:

  1. Compare Products
  2. Default welcome msg!
  3. My Account
  4. My Wish List
  5. Create an Account
  6. Sign In

I need to know how, from my custom theme (I want to stay safe from the overwrites that occur when updating Magento), I could have only:

  1. My Cart
  2. My Wish List
  3. Sign In

In app/design/frontend/vendor/themename/Magento_Theme/layout/default.xmlI have changed:

<referenceBlock name="top.links">
        <block class="Magento\Theme\Block\Html\Header" name="header" as="header" before="-">
            <arguments>
                <argument name="show_part" xsi:type="string">welcome</argument>
            </arguments>
        </block>
</referenceBlock>

into:

<referenceBlock name="top.links">
        <block class="Magento\Theme\Block\Html\Header" name="header" as="header" before="-">
            <arguments>
                <argument name="show_part" xsi:type="string">welcome</argument>
            </arguments>
        </block>
        <referenceBlock  name="my-account-link" remove="true"/>
        <referenceBlock  name="compare-products-link" remove="true"/>
        <referenceBlock  name="wishlist_link" remove="true"/>
</referenceBlock>

With no effect.

How can I achieve this goal? Thank you!

Was it helpful?

Solution

You need to add a custom layout file to your theme.

app/design/frontend/vendor/themename/Magento_Theme/layout/default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="top.links">
        <block class="Magento\Theme\Block\Html\Header" name="header" as="header" before="-">
            <arguments>
                <argument name="show_part" xsi:type="string">welcome</argument>
            </arguments>
        </block>
    </referenceBlock>

    <referenceBlock name="catalog.compare.link" remove="true" />
    <referenceBlock name="header" remove="true" />
    <referenceBlock name="register-link" remove="true" />
    <move element="top.links" destination="header-wrapper" after="logo" />
    </body>
</page>

There you can reference the elements you want to remove and do so with the attribute remove="true".

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top