I have added CMS page link to the top menu by following the below tutorial:


Since one of the custom menu items would be Home, so it should be the first item in the menu.

I want to know that how can I make some custom menu item as the first item in the top menu using the code in the tutorial.

Update: Suppose, I have 2 custom menu items, say Home and Contact. I want to make Home as the first menu item and Contact as the last menu item. Is it possible with a single plugin class? or I have to write 2 different plugins to achieve this goal?

Please help.

  • Need to change position of menu? – Dharmendra Jadav Jul 24 '18 at 12:53
  • yes, I need to set the first position for the Home menu item. – Mohit Kumar Arora Jul 24 '18 at 13:00
  • With same way or any other way? – Suresh Chikani Jul 24 '18 at 13:12

There is a issue with plugin order

In default Magento already plugin define in vendor/magento/module-catalog/etc/di.xml

<type name="Magento\Theme\Block\Html\Topmenu">
    <plugin name="catalogTopmenu" type="Magento\Catalog\Plugin\Block\Topmenu" />

And we created custom plugin in app\code{VendorName}{ModuleName}\etc\di.xml

<type name="Magento\Theme\Block\Html\Topmenu">
    <plugin name="add_cms_menu" type="{VendorName}{ModuleName}\Plugin\Topmenu" sortOrder="0" />

That means core and custom plugin, both are same exist with same sort order.

If you want to display custom menu just before category menu, sort order required minimum values to core value.

Use below code for plugin and check you custom menu

<type name="Magento\Theme\Block\Html\Topmenu">
    <plugin name="add_cms_menu" type="{VendorName}{ModuleName}\Plugin\Topmenu" sortOrder="-1" />

I hope it will be useful for you. Let me know if not working

  • Great. I did not think about this. One more question. I want to add Home at the first place and Contact Me at the last place. Is it possible with a single plugin? – Mohit Kumar Arora Jul 24 '18 at 14:02
  • If not, I will still upvote your answer. – Mohit Kumar Arora Jul 24 '18 at 14:03
  • Accept my answer if resolve current asked issue. – Suresh Chikani Jul 24 '18 at 14:25
  • I have upvoted and accepted.Now can you answer on my question which I asked in the comment? – Mohit Kumar Arora Jul 25 '18 at 5:25
  • I have updated my question now. – Mohit Kumar Arora Jul 25 '18 at 5:30

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.