admin管理员组

文章数量:1297050

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');

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');
Share Improve this question asked Sep 1, 2017 at 11:19 cboycboy 371 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: Primary menu shortcode name