Today I came across a weird situation: I needed to place a navigation menu in the content of a page. A shortcode was the obvious solution, but there doesn’t appear to be one built in for menus. I created this one very quickly:
function print_menu_shortcode($atts, $content = null) { extract(shortcode_atts(array( 'name' => null, ), $atts)); return wp_nav_menu( array( 'menu' => $name, 'echo' => false ) ); } add_shortcode('menu', 'print_menu_shortcode');
Place this in functions.php, then use [menu name="main-menu"] to call the menu in your content (replacing "main-menu" with your menu’s slug, of course).
и код, если для меню еще нужно указать отдельный класс:
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('menu', 'print_menu_shortcode'); And in the content [menu name="-your menu name-" class="-your class-"]