0

I have a shortcode that will put a menu where I want it, but it only works on the primary menu. I don't want to use the shortcode for the primary menu, I would like to create a new menu called shortcodemenu and have the shortcode call it when it is used.

function print_menu_shortcode($atts, $content = null) {
extract(shortcode_atts(array( 'name' => null, 'class' => null ), $atts));
return wp_nav_menu( array( 'menu' => $name, 'menu_class' => $class, 'echo' => false ) );
}
add_shortcode('shortcodemenu', 'print_menu_shortcode');

1 Answer 1

0

You basically have everything set. You simply need to call the shortcode:

[shortcodemenu menu="slug-of-your-menu"]

Remember to use the SLUG of the menu you want to show instead of its name.

1
  • 1
    Welcome to Wordpress Stack Exchange! Please note that you must disclose your affiliation when linking to a website; for more information, read How not to be a spammer.
    – Glorfindel
    Commented Sep 1, 2017 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.