2

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!

3
  • Do you mean to say that you want to add your custom toplinks in your custom theme so when you upgrade magento version, it doesn't lose your changes? Nov 20, 2017 at 12:18
  • Yes, this is what I want. Nov 20, 2017 at 12:21
  • I just tried my code, it is working for me, the only thing is that i got the name for the wishlist-link wrong. Did you try to clear the cache via php bin/magento cache:clean ?
    – TrytoFly
    Nov 21, 2017 at 9:11

1 Answer 1

0

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".

5
  • I do have a default.xml file. Nov 20, 2017 at 12:31
  • With what content? Did you already try to remove the links via your layout file?
    – TrytoFly
    Nov 20, 2017 at 12:49
  • With <block class="Magento\Theme\Block\Html\Header" name="header" as="header" before="-"> <arguments> <argument name="show_part" xsi:type="string">welcome</argument> </arguments> </block> See question. I have edited it Nov 20, 2017 at 12:52
  • Try to just add what you want deleted after your block declaration, inside your default.xml (see my edited answer).
    – TrytoFly
    Nov 20, 2017 at 13:37
  • The code <referenceBlock name="compare-products-link" remove="true"/> does not work. The "Compare Products" is still there. Dec 14, 2017 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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