Magento 2 UB Mega Menu
I. Installation Prerequisites
UB Mega Menu is native with Magento 2.x. Please make sure your system meets the Magento 2 System requirements: here.
II. Download Packages
Navigate to your profile at Ubertheme to download UB Mega Menu extension:
III. Manual Installation
NOTE: If your deploy:mode is production, you need to switch to Developer mode first (optional). Open your Terminal window, go to Magento 2 directory and run command below:
- php -f bin/magento deploy:mode:set developer
Step 1. Unzip the download package somewhere on your local PC. Then copy the ‘app’ directory and paste into root directory of your Magento 2


Step 2. Open your terminal and go to the Magento directory. In this directory, run the following commands:
- php -f bin/magento module:enable -c Ubertheme_UbMegaMenu
- php -f bin/magento setup:upgrade

Step 3 (optional): Run code compilation using command below. This helps to improve your site performance after installation:
- php -f bin/magento setup:di:compile

Once you finish the last command to flush cache, you have UB Mega Menu installed and ready for your use.
IV. Magento 2 Mega Menu Configuration
Our Magento 2 Mega Menu supports 7 styles:
- style-default
- style-1
- style-2
- style 3
- style 4 (Full Width)
- style 5
- style 6
- Vertical menu
1. How to call UB Mega Menu
Before going into steps to create and configure menu items as per our demo, let’s learn about general settings of our Magento 2 Mega Menu and 3 ways it supports to create menu item.
1.1. General Magento 2 mega menu settings
In your Magento backend, go to Content | (UB Mega menu) Settings, you can see the Basic settings of UB Mega Menu. We can leave this configuration as default for now.
UB Mega Menu Params
[show_number_product] | Value 0 or 1. Default is 0. |
[default_mega_col_width] | The width of a Mega Column (px). Default is 200 |
[mega_content_visible_in] | Example: desktop, tablet, mobile (ready from v1.0.1) |
[end_level] | The max level of menu item to show. Default is 10. |
[enable_font_awesome] | Select “Yes” to enable font awesome. |
[auto_sync_category_menu_item] | If Yes, whenever you create a new sub-category associated with a parent category available in your mega menu, a submenu item for such sub-category will automatically be created. Default value is Yes. |
[auto_sync_cmspage_menu_item] | If Yes, when you remove a CMS page, menu items associated with such CMS page will be automatically deleted. Default value is No. |
1.2 Three options to create UB Mega Menu menu item
1.2.1 -- Settings and show a UB Mega Menu via Widgets management module (Content/Widgets)

1.2.2 -- call block
Shortcode to show in CMS Blocks
{{block class="Ubertheme\UbMegaMenu\Block\Menu" name="ub.mega.menu1" menu_key="YOUR_MENU_KEY_HERE"}}
1.2.3 -- Call in XML
Shortcode to call in XML:
<referenceContainer name="page.top"><block class="Ubertheme\UbMegaMenu\Block\Menu" name="ub.megamenu.leftmenu1" ifconfig="ubmegamenu/general/enable"> <arguments> <argument name="menu_key" xsi:type="string">top-menu</argument> <argument name="addition_class" xsi:type="string"></argument> </arguments></block></referenceContainer>
2. UB Mega Menu Configuration
This section provides detailed instruction to configure each style of Magento 2 mega menu as per our demo site.
Important! You need to clear your cache in Magento after you create a new menu item or make any change following our configuration steps below.
When prompted, click the Cache Management link in the system message, and tap ‘Flush Cache Storage’ button to refresh the invalid cache. Or in your admin dashboard, you simply click System | Cache Management and flush cache.
For UB Mega Menu ver1.1.3 and later, we added a new cache enhancement that allows to cache menu data on all pages, including non-cacheable pages (customer account…). Thus, it requires to use Flush cache option to apply any change you make. You can either use the CLI command: php bin/magento cache:flush or tap ‘Flush Cache Storage’ button as mentioned above.
2.1 Default style

Step 1 -- Create menu group
In the Magento backend, navigate to Content | (UB Mega Menu) Manage Menu, then click Add New Menu. In the popup, you can configure as per this screenshot (Make sure you insert menu key as main-menu
). Once done, you should see the new menu group visible as illustration (3) in the following screenshort:

Step 2 -- Create Magento 2 mega menu item
Supposed that you have some sample products in place already, now we start to create menu items for the mega menu. In the same Menu Group panel, go to Select | Manage Menu Items:

Step 2.1 -- Create Service and its sub-menu items:

NOTE: When you create UB Mega Menu for the first time, you will not see any menu item in place yet. The above-mentioned screenshot just gives you an illustration about the menu hierarchy after you create those menu items.
Click Add New Menu Item button to create each of menu item, and follow configuration below:
- Service: Configuration steps -- menu setting 1 > menu setting 2
NOTE: when you create multiple columns, you need to set the width of each column in px. For instance:
col1=200
col2=200
col3=200
col4=600
And wrapper of the column width (px), for instance: 600
Make sure in the Setting 2 step, you insert custom CSS classstyle-default
- Gear: Configuration steps -- menu setting 1 > menu setting 2
NOTE: When you check the setting 2, in the field Description click Show / Hide Editor button, then click Insert Image button and upload the image at your choice. Once you upload image (eg. clothing.jpg) successfully, the image param should follow this format:<div><img src=”{{media url=”wysiwyg/ubmegamenu/clothing.jpg”}}” alt=”Magento 2 Mega Menu” /> /></div> - Bags: Configuration steps -- menu setting 1 > menu setting 2
- Apply similar setting of Bags for other sub-menu items of Gear
Step 2.2 -- Create Men, Women and their sub-menu items
Follow similar steps and settings as per Gear menu and its sub-menu items.
Step 2.3 -- Create Hot Product
Product’s Configuration steps -- Setting 1 > Setting 2 > Setting 3
NOTE:
In the Setting 2 step above, navigate to Custom Content | Click Show / Hide Editor button, and click Insert Widget button. Then follow the setting as per the Setting 3 screenshot.
Alternatively, in the Setting 2, navigate to the field Custom Content, click Show / Hide Editor button, and insert the sample snippet below which will call a sample Hot Products widget. Please note the sample code applies for a fresh Magento instance with sample data only.
<p>{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" title="Hot Products" show_pager="0" products_count="3" template="product/widget/content/grid.phtml" conditions_encoded="a:1:[i:1;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]]"}}</p>
2.2 Style-1

Step 1 -- Create Training and its sub-menu items:

Click Add New Menu Item button to create each of menu item, and follow configuration below:
- Training: Configuration steps -- menu setting 1 > menu setting 2
NOTE: when you create multiple columns, you need to set the width of each column in px. For instance:
col1=400
col2=300
And wrapper of the column width (px), for instance: 700
Make sure in the Setting 2 step, you insert custom CSS classstyle-1
- Column01: Configuration steps -- menu setting 1 > menu setting 2
NOTE: when you create multiple columns, you need to set the width of each column in px. For instance:
col1=200
col2=200
col3=400
And wrapper of the column width (px), for instance: 400 - Gear: Configuration steps -- menu setting 1 > menu setting 2
NOTE: When you check the setting 2, in the field Description click Show / Hide Editor button, then click Insert Image button and upload the image at your choice. Once you upload image (eg. traning.jpg) successfully, the image param should follow this format:
- Bags: Configuration steps -- menu setting 1 > menu setting 2
- Apply similar setting of Woman bags for other sub-menu items of Clothing
Step 2.2 -- Create Men and their sub-menu items
Follow similar steps and settings as per Gear menu and its sub-menu items.
Step 2.3 -- Insert Free Shiping Banner into Mega menu
Create Free Shiping item (by clicking Add New Menu Item) as a sub-menu of Training > Column01 following configuration steps: Setting 1 > Setting 2
Step 2.4 -- Create Hot Product and Best Seller menu items
Column02: Configuration steps -- Setting 1 > Setting 2 > Setting 3
NOTE: In the Setting 2 step, navigate to Custom Content | Click Show / Hide Editor button, and click Insert Widget button. Then follow setting as per the Setting 3 screenshot to load Hot Product widget. You can do the same to load the Best Seller widget.
Alternatively, in the Setting 2 screenshot above, in the field Custom Content, click Show / Hide Editor button, then insert the sample snippet below which will call both sample Hot Product and Best Products widgets. Please note the sample code applies for a fresh Magento instance with sample data only.
<p>{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" title="Best Product" show_pager="0" products_count="2" template="product/widget/content/grid.phtml" conditions_encoded="a:2:[i:1;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`value`;s:1:`8`;]]"}}</p> <p>{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" title="Hot Product" show_pager="0" products_count="1" template="product/widget/content/grid.phtml" conditions_encoded="a:2:[i:1;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`value`;s:1:`4`;]]"}}</p>
2.3 Style-2

Step 1 -- Create Clothing and its sub-menu items
We do similar steps as per Style-1 to create menu items.

Click Add New Menu Item button to create each of menu item, and follow configuration below:
- Men: Configuration steps -- Setting 1 > Setting 2
NOTE: Make sure you add CSS classstyle-2
in the setting #2 step.
And wrapper of the column width (px), for instance: 700 - Column01: Configuration steps -- Setting 1 > Setting 2
NOTE:
-- when you create multiple columns, you need to set the width of each column in px. For instance:col1=140
col2=140
col3=140
col4=280
-- And wrapper of the column width (px), for instance: 700
-- When you check the setting 2, in the field Description click Show / Hide Editor button, then click Insert Image button and upload the image at your choice. Once you upload image successfully, the image param should follow this format:<div class="full-banner"><img src="{{media url="wysiwyg/ubmegamenu/banner-01.jpg"}}" alt="Magento 2 mega menu" /> <h3>New arrivals</h3> <h4>Discover the women collections</h4> </div>
- Women: Configuration steps -- Setting 1 > Setting 2
- What’s New: Configuration steps -- Setting 1 > Setting 2
- Apply similar settings of What’s New in for other sub-menu items of
Tops and Shorts menu items follow the same steps.
Step 2 -- Create Product’s menu item
This item is actually a Magento 2 widget (Catalog New Product List) being loaded into mega menu. Click Add New Menu Item again, to create Best Product item and follow these configuration steps: Setting 1 > Setting 2 > Setting 3
NOTE:
Alternatively, in the Setting 2 screenshot above, in the field Custom Content, click Show / Hide Editor button, then insert the sample snippet below which will call a sample Best Products widget. Please note the sample code applies for a fresh Magento instance with sample data only.
<p>{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" title="Best Products" show_pager="0" products_count="2" template="product/widget/content/grid.phtml" conditions_encoded="a:2:[i:1;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`value`;s:1:`3`;]]"}}</p>
2.4 Style 3 (one-column)

We do similar steps as per Style-1 to create menu items.

Click Add New Menu Item button to create each of menu item, and follow configuration below:
2.5 Style 4 (Full Width)

Step 1 -- Create Sale and its sub-menu items
We do similar steps as per Style-1 to create menu items.

Click Add New Menu Item button to create each of menu item, and follow configuration below:
- Sale: Configuration steps -- Setting 1 > Setting 2
NOTE:Full width mega menu is a new feature introduced in UB Mega Menu ver 1.1.2. You will see a new setting ‘Set Base Width’ with two values:
- Fixed Width (px)
- Dynamic Width (%)
In order to set the mega menu to full width, you need to set the Base Width as ‘Dynamic Width (%)’ first. Then, you specify the individual column widths:
- If you have 1 column in your mega menu, your column width equals to 100%
- If you have 5 columns in your mega menu and set the ‘Grid Column Submenu’ blank, each column width equals to 20%.
- If you want to set column width individually, enter the percentage value for each respective column under the ‘Grid Column Submenu’ field. For instance:
- col1=25
- col2=25
- col3=25
- col4=25
- col5=100
With this configuration, your mega menu will end up with a Full Width mega menu where the first 4 columns will be located on the first row, and the fifth column on the second row with max 100% width.
- Gear: Configuration steps -- Setting 1 > Setting 2
- Bags: Configuration steps -- Setting 1 > Setting 2
- Bras & Tanks: Configuration steps -- Setting 1 > Setting 2
- Apply similar settings for the rest of sub-menu items
Step 2 -- Create What’s New menu item
Click Add New Menu Item again, to create What’s New item and follow these configuration steps: Setting 1 > Setting 2
NOTE:
Alternatively, in the Setting 2 screenshot above, in the field Custom Content, click Show / Hide Editor button, then insert the sample snippet below. Keep in mind that this sample code applies to a fresh Magento instance with sample data only.
<div class="intro-megamenu"> <div class="intro">Our Magento 2 mega menu is developed from the ground up. Simple yet powerful enough to create highly customisable Magento 2 mega menu, either horizontal or vertical for your store. With many goodies in place like Drag n Drop admin interface, flexible configuration options, you can show off your product categories and sub-categories in a multi-column drop down menu. You can promote items, banners and clips right in the Magento 2 Mega Menu, just a few clicks away.</div> <div class="func-01"><img src="{{media url="wysiwyg/ubmegamenu/image03.jpg"}}" alt="Multiple Column Magento 2 Mega Menu" /> <p class="title">Multiple Column Magento 2 Mega Menu</p> <p>Easier than ever to build professional multiple column layout to show off all of your categories and subcategories. Shoppers can see all of featured product options or navigate from pages to pages with ease.</p> </div> </div>
2.5 Style 5 (Stacked category dropdown)
This is a new menu type introduced in UB Mega Menu ver1.1.3. On mouse hover, each primary category expands as a mega menu with corresponding level-2 and level-3 subcategories. The mega menu is visually divided into two columns (one for main categories, and other column is for their sub categories).

We follow similar steps as per the Style-1 to create menu items.

Click Add New Menu Item button to create each of menu item, and apply the following configurations:
- Home: Configuration steps -- Setting 1 > Setting 2
NOTE:
-- Make sure you set ‘Set Base Width’ as Dynamic Width(%) and Wrapper Width: 100.
-- In the Setting 2 step, you insert the custom CSS classstyle-tabs
. - Column 1: Configuration steps -- Setting 1 > Setting 2
- Shorts: Configuration steps -- Setting 1 > Setting 2
NOTE:
-- Make sure in the Setting 2 step, you insert the custom CSS classtab-head
. - Gear: Configuration steps -- Setting 1 > Setting 2
- Bags: Configuration steps -- Setting 1 > Setting 2
- You simply apply similar settings for the rest of sub-menu items
2.6. Style 6 (Adding thumbnails to UB Mega Menu)
There are two options to add a thumbnail to a menu item:
- Using the Category image as the thumbnail of a menu item.
- Adding a custom image via Custom Content field of the menu item.
2.6.1. Using category image as the thumbnail
To display the thumbnails of menu items using the category image, please follow steps below:
Step 1: Go to CATALOG | Categories, click Upload button to upload image that you want to use for the category.

Step 2: Create a menu item with the Catagory Page type, select the category that you configure in the step 1 and enable “Menu Thumbnail” to show the thumbnail.

2.6.2. Adding thumbnails via Custom Content field

You follow similar steps as per Style-1 to create menu items.

Click Add New Menu Item button to create each of menu item, and follow the configuration below:
- Home: Configuration steps -- Setting 1 > Setting 2
NOTE:
-- Make sure you set ‘Set Base Width’ as Dynamic Width(%) and Wrapper Width: 100.
-- In the Setting 2 step, you insert the custom CSS classstyle-tabs
. - Column 1: Configuration steps -- Setting 1 > Setting 2
- Gear: Configuration steps -- Setting 1 > Setting 2
NOTE:
Make sure in the Setting 2 step of the Gear menu item, you insert the custom CSS class tab-head
.
And in the Custom Content field, click Show / Hide Editor button, then insert the sample snippet below. Custom Content field will define the images that you want to display as the thumbnails of the submenu items.
<div class="mega-with-thumb"> <ul class="mega-menu"> <li class="mega"><a class="mega" href="{{config path="web/unsecure/base_url"}}gear.html"><img src="{{media url="wysiwyg/ubmegamenu/thumb/thumb01.jpg"}}" alt="" /><span class="menu-title">Bengal Tiger</span></a></li> <li class="mega"><a class="mega" href="{{config path="web/unsecure/base_url"}}women/tops-women.html"><img src="{{media url="wysiwyg/ubmegamenu/thumb/thumb02.jpg"}}" alt="" /><span class="menu-title">Fruits Hanging</span></a></li> <li class="mega"><a class="mega" href="{{config path="web/unsecure/base_url"}}women/tops-women/tanks-women.html"><img src="{{media url="wysiwyg/ubmegamenu/thumb/thumb03.jpg"}}" alt="" /><span class="menu-title">Autumn Season</span></a></li> <li class="mega"><a class="mega" href="{{config path="web/unsecure/base_url"}}women/bottoms-women/pants-women.html"><img src="{{media url="wysiwyg/ubmegamenu/thumb/thumb04.jpg"}}" alt="" /><span class="menu-title">Butterflies</span></a></li> <li class="mega"><a class="mega" href="{{config path="web/unsecure/base_url"}}women/tops-women/tees-women.html"><img src="{{media url="wysiwyg/ubmegamenu/thumb/thumb05.jpg"}}" alt="" /><span class="menu-title">Heart Red</span></a></li> <li class="mega"><a class="mega" href="{{config path="web/unsecure/base_url"}}training.html"><img src="{{media url="wysiwyg/ubmegamenu/thumb/thumb06.jpg"}}" alt="" /><span class="menu-title">The eye</span></a></li> <li class="mega"><a class="mega" href="{{config path="web/unsecure/base_url"}}women.html"><img src="{{media url="wysiwyg/ubmegamenu/thumb/thumb07.jpg"}}" alt="" /><span class="menu-title">Smoking</span></a></li> <li class="mega"><a class="mega" href="{{config path="web/unsecure/base_url"}}women/tops-women.html"><img src="{{media url="wysiwyg/ubmegamenu/thumb/thumb08.jpg"}}" alt="" /><span class="menu-title">Red Squirrel</span></a></li> <li class="mega"><a class="mega" href="{{config path="web/unsecure/base_url"}}women/bottoms-women.html"><img src="{{media url="wysiwyg/ubmegamenu/thumb/thumb09.jpg"}}" alt="" /><span class="menu-title">Scarlet</span></a></li> <li class="mega"><a class="mega" href="{{config path="web/unsecure/base_url"}}women/bottoms-women/shorts-women.html"><img src="{{media url="wysiwyg/ubmegamenu/thumb/thumb10.jpg"}}" alt="" /><span class="menu-title">Tiger Famile</span></a></li> </ul> </div>
2.7 Style 7 (Vertical menu)

Some stores might need vertical menu, instead of the top main menu. It’s possible for UB Mega menu to create the sidebar one column menu (vertical).
Step 1: Create menu group with menu key ub-left-menu for vertical menu, then add menu item as you wish:

(If you are new to Magento, scroll back to section 2.1 Default Style to learn on steps to create menu group)
Step 2:
In your Magento admin, navigate to Content | Widget, then click Add Widget, and configure as follows:


Once done, simply add your own menu items the same way we do in the Top Menu above.
NOTE:
The UB Mega Menu v.1.1.5 supports a new extra class flattened-menu. Once the flattened-menu is added to the first level menu item, the vertical menu should look like this:

In order to use this newly added extra class: flattened-menu, please note the following required conditions:
- Applied to Vertical menu only
- Applied to the first level menu item only
- Make sure you set Enable Group Item of the first level menu item to Yes (Menu item settings > Mega Settings > Enable Group Item: Yes)
V. Import Categories into menu
Import categories into UB Mega Menu
Supposed that you have existing product categories, you can simply import all categories or a few specific categories into your Magento 2 mega menu. If you select to import all categories, UB Mega Menu (starting from version 1.0.3) allows to import categories and sub-categories recursively. That means, your whole category tree is fully imported and reserved.
NOTE: Only Categories with ‘Enable Category’ and ‘Include in Menu’ enabled are imported.
The import steps are simple as follows:
In the same Menu Group panel, go to Select | Manage Menu items. In the Menu item panel, click Import Categories, you’ll be directed to a pop up window. In the ‘Select Import Type’ field, specify the option you wish to import.

In case you import a few specific categories, simply fill in and select the name of categories you wish, then proceed import as per screenshot below.

Then (optional) assign the parent menu item to which the selected categories are imported and click ‘Import Categories’ button. Once done, your categories tree should be in place. See the sample below for reference:

Then you should go to your admin dashboard, click System | Cache Management and tap ‘Flush Cache Storage’ button to flush cache. Now open up menu on your frontend, you should see them in place:

EXTRA NOTE:
(New improvements in UB Mega Menu 1.0.4 and later)
During your development process, chances are that you might need to add or delete a huge list of menu items. UB Mega menu now allows you to remove (recursive) menu and sub-menu items easily. For instance, if you delete Gear menu item as shown in the screenshot below, all its sub-menu items will be removed too. You can delete each single sub-menu item though.

Or when you change the URL key or add a new sub-category, it will be automatically synced to the menu. And a menu item will no longer exist if its linked category is deleted.
Below you can find an example of a newly added sub-category:
- In your Magento admin, navigate to Category | Add Subcategory and create a new Sub-category (eg. Shoes under Gear category), then click Save button.

- Supposed that the Gear category menu item is already in place, then the new subcategory Shoes should be automatically synced to your Gear menu item.

V. Manual Un-Installation
If you want to have Magento 2 Mega Menu extension uninstalled, please follow steps below:
- Step 1: [Important] Remove related widgets if they were created
Go to your Backend | Content | Widget, delete all created widgets with Widget Type UB Mega Menu
- Step 2: Disable UB Instant Layered Navigation module and clean associated database tables
-- Open your terminal, go to your Magento2 folder <your magento install path> and run the following CLI commands:
php -f bin/magento maintenance:enable
php -f bin/magento deploy:mode:set developer
php -f bin/magento module:disable -c Ubertheme_UbMegaMenu
rm -rf app/code/Ubertheme/UbMegaMenu
-- Open your Mysql cpanel (eg. PHPMyAdmin), and run the following SQL:
NOTE: Make sure you replace with your own <table_prefix>:
DELETE FROM '<table_prefix>setup_module` WHERE `module`= 'Ubertheme_UbLayeredNavigation'
DELETE FROM `<table_prefix>setup_module` WHERE `module` = 'Ubertheme_UbMegaMenu';
DROP TABLE `<table_prefix>ubmegamenu_item`;
DROP TABLE `<table_prefix>ubmegamenu_group_store`;
DROP TABLE `<table_prefix>ubmegamenu_group`;
- Step 3: Once done, run the following commands:
NOTE: You can still keep the developer mode if you continue development process. Otherwise, run the following commands to switch to production mode:
php bin/magento deploy:mode:set production
php bin/magento maintenance:disable