Categories
WordPress

My method to install Max Mega Menu on production without flickering

Max Mega Menu is a wonderfull WordPress plugin to create multi level menu. But you need a lot of time to create a great menu, and the plugin ask you to save a lot of time before your satisfy with what you wanted to achieve. Each time you save an item, the visitor see the menu change on the frontend.

So, how to secretly install the menu without impact your visitor ? I finally find a way to do that. The method is to add an if else statement to display mega menu for only you, and the classic menu you are using to your visitors.

First

In header.php , check if the menu is loaded and add a class in body will allow you to add some special style you need in your css file. Just in case you need it.

<?php
if ( function_exists('max_mega_menu_is_enabled') && max_mega_menu_is_enabled('primary') && ($_GET['menu']==="demo") ){
	$class.=' maxmegamenu';
}
?>
<body <?php body_class($class); ?>>

Check if the Max Mega Menu is in used and display only if the param menu is present in the url.

<?php if ( function_exists('max_mega_menu_is_enabled') && max_mega_menu_is_enabled('primary') && ($_GET['menu']==="demo") ) : ?>
<?php wp_nav_menu( array( 'theme_location' => 'primary') ); ?>
<?php else: ?>
//call your previous menu
<?php endif; ?>

With a simple GET, you can now work in the creation of your mega menu, and display by default your current menu to your visitors. https://example .com?menu=demo

Second

Create a new menu in appearance, and follow the documentation of megamenu.com.

Leave a Reply