Using the Shortcode
The menu will work straight out of the box as soon as it has been activated as long as the
wp_footer() calls are found in your
footer.php files respectively.
Sometimes however you may want a bit more control over the menu, like setting different options based on certain conditions – including different menus on different pages or for placing it inside a specific DOM element.
Using the technique above you can also use different menus for different languages all using the same plugin with the same settings.
This can all be achieved by using the built in shortcode and as with everything else with the plugin it is very easy to use.
Enable the Shortcode
The first thing you need to do is enable the shortcode option itself as without it the shortcode will not be active and you will just see text displayed on your site when trying to use it.
The option to turn the Shortcode on can be found in the
Advanced tab, under the
Technical section, called
As you can see from the image above the shortcode is very easy to turn on and with if you get a few extra options for changing particular information on the fly – a small table of these is shown below:
|menu_to_use||Change which menu is displayed.|
|theme_location_menu||Change the theme location menu that is displayed. This will overwrite the
|menu_title||Change the menu title.|
|menu_title_link||Change the menu title link location.|
|button_title||Change the button text.|
Using the Shortcode
Using the shortcode is done the same as any other shortcode in WordPress and you can find out more about them from the WordPress pages by clicking here.
You can either use the shortcode in your pages by simply placing the text
[responsive_menu_pro] in your pages depending on which version you have installed, alternatively you can include this directly in your template files (usually inside header.php) as below:
<?php echo do_shortcode('[responsive_menu]'); ?>
and for the pro version:
<?php echo do_shortcode('[responsive_menu_pro]'); ?>
Using custom options
The custom options mentioned earlier are easily used by simply attaching them to the shortcode as below:
<?php echo do_shortcode('[responsive_menu_pro menu_title="Alternative Title"]'); ?>;
Doing the above is a great way of customising the menu for individual pages, as you can change the menu title to something different on blog pages to actual pages.
Doing the below you can change the menu that is used by the plugin entirely.
<?php echo do_shortcode('[responsive_menu_pro menu_to_use="menu-2"]'); ?>
Different Menu for Logged In Users
If you would like to show a different menu (with different options) for logged in users, you could do the following:
<?php if(is_user_logged_in()) echo do_shortcode('[responsive_menu]'); else echo do_shortcode('[responsive_menu menu_to_use="logged-in-menu"]'); ?>
Different Menus for Different Languages
Another common request is to have the ability to show different menus for different languages on your site.
Again, the below example will need to be modified and added to your
footer.php file, with your own custom logic in place of the
get_locale() switch function and custom menu options in the code below:
<?php switch(get_locale()) : case 'en_EN' : $menu = 'english-menu'; break; case 'es_ES' : $menu = 'spanish-menu'; break; case 'fr_FR' : $menu = 'french-menu'; break; default : $menu = ''; endswitch; echo do_shortcode('[responsive_menu menu_to_use="' . $menu . '"]'); ?>
Although this page is relatively short, don’t be fooled – the shortcode option gives you great flexibility and the only limit is your imagination!