Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simonlk/3984510 to your computer and use it in GitHub Desktop.
Save simonlk/3984510 to your computer and use it in GitHub Desktop.
Create short code for menu items with arguments like wp_nav_menu and allow short codes to be added to widgets
// Function that will return our Wordpress menu
// from http://www.cozmoslabs.com/1170-wp_nav_menu-shortcode/
function list_menu($atts, $content = null) {
extract(shortcode_atts(array(
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => 0,
'walker' => '',
'theme_location' => ''),
$atts));
return wp_nav_menu( array(
'menu' => $menu,
'container' => $container,
'container_class' => $container_class,
'container_id' => $container_id,
'menu_class' => $menu_class,
'menu_id' => $menu_id,
'echo' => false,
'fallback_cb' => $fallback_cb,
'before' => $before,
'after' => $after,
'link_before' => $link_before,
'link_after' => $link_after,
'depth' => $depth,
'walker' => $walker,
'theme_location' => $theme_location));
}
//Create the shortcode
add_shortcode("listmenu", "list_menu");
// do short codes in widgets
add_filter('widget_text', 'do_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment