Using the Shortcode

The menu will work straight out of the box as soon as it has been activated as long as the wp_head() and wp_footer() calls are found in your header.php and 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 Use Shortcode?

Shortcode Options

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:

OptionDescription
menu_to_useChange which menu is displayed.
theme_location_menuChange the theme location menu that is displayed. This will overwrite the menu_to_use option above.
menu_titleChange the menu title.
menu_title_linkChange the menu title link location.
button_titleChange 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] or [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]<?php echo do_shortcode('[responsive_menu]'); ?>[/php]

and for the pro version:

[php]<?php echo do_shortcode('[responsive_menu_pro]'); ?>[/php]

Using custom options

The custom options mentioned earlier are easily used by simply attaching them to the shortcode as below:

[php]<?php echo do_shortcode('[responsive_menu_pro menu_title="Alternative Title"]'); ?>;[/php]

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]<?php echo do_shortcode('[responsive_menu_pro menu_to_use="menu-2"]'); ?>[/php]

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]<?php if(is_user_logged_in()) echo do_shortcode('[responsive_menu]'); else echo do_shortcode('[responsive_menu menu_to_use="logged-in-menu"]'); ?>[/php]

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 header.php or 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]<?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 . '"]'); ?>[/php]

Although this page is relatively short, don’t be fooled – the shortcode option gives you great flexibility and the only limit is your imagination!

Was This Article Helpful?

-3
Related Articles
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published. Required fields are marked *