Example. Top menu:

Comment manually children category in topmenu.phtml:

<?php /* @escapeNotVerified */ /*echo $block->getChildHtml();*/ ?>

After click or hover - uncomment this code:

<?php /* @escapeNotVerified */ echo $block->getChildHtml(); ?>

What is the best solution? I want to reduce the number of links in the body of html, but I don't want to hide the top menu (I believe that this should be implemented in the basic functionality of the Magento).

2 Answers 2


Php code is executed on the server side and send to the browser. Hovering is done inside the browser and does not hit the server. Clicking might if there is additional request. If you want to show additional menu after hovering/clicking you need to render it in html, set display:none on it and prepare event handler in javascript to remove toggle that style when the action happens.


If you want to load additional part later you have 2 options:

1) Create an ajax request on clicking/hovering and prepare rest endpoint or a controller that will return the requested part and then inject it to the DOM.

2) If the above will be too slow in execution you can instead of building actual menu create a json array with links and build the menu on the fly with js when user wants to use the menu.

  • Menu with the links will still be visible in the body of html. There is no sense in doing with display: none. It is necessary, that in html there were no links to the menu, but the menu should be loaded on click / hover. It seemed to me that it was more correct to do with php Mar 18, 2017 at 22:13
  • @АлександрЖарский check the update in my answer
    – Zefiryn
    Mar 19, 2017 at 10:28

Try to remove this block from your theme page, for example: catalog/product/view (catalog_product_view.xml).

Insert this peace of code on your customised XML.

<referenceBlock name="catalog.topnav" remove="true"/>
  • Thank, but I have a different goal. I need to hide the menu links from html, but so that when I click or hover - the menu is displayed. (SEO is recommended to have on the page no more than 100 links. I'm looking for a solution.) Mar 18, 2017 at 22:08

Your Answer

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

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