Skip to content

Instantly share code, notes, and snippets.

@mrfoxtalbot
Last active July 27, 2016 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrfoxtalbot/1712097e35c1e2c295126d6f6c135bd7 to your computer and use it in GitHub Desktop.
Save mrfoxtalbot/1712097e35c1e2c295126d6f6c135bd7 to your computer and use it in GitHub Desktop.
Insert a WordPress menu using a shortcode
<?php
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 then use this shortcode [menu name="main-menu"] (changin "main-menu" with your menu name)
@mrfoxtalbot
Copy link
Author

mrfoxtalbot commented Jul 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment