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!

  • 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? – Dinesh Yadav Nov 20 '17 at 12:18
  • Yes, this is what I want. – Razvan Zamfir Nov 20 '17 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 '17 at 9:11
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".

  • I do have a default.xml file. – Razvan Zamfir Nov 20 '17 at 12:31
  • With what content? Did you already try to remove the links via your layout file? – TrytoFly Nov 20 '17 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 – Razvan Zamfir Nov 20 '17 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 '17 at 13:37
  • The code <referenceBlock name="compare-products-link" remove="true"/> does not work. The "Compare Products" is still there. – Razvan Zamfir Dec 14 '17 at 13:36

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.