Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jayseventwo/5668466 to your computer and use it in GitHub Desktop.
Save jayseventwo/5668466 to your computer and use it in GitHub Desktop.
Add a WordPress custom menu to a page/post using a shortcode - add to functions.php
/* --------------------------------------------------add custom menu to page using shortcode
add [custommenu menu=Menu-name-here] to page*/
function custom_menu_shortcode( $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
)
);
}
/**
* Adds the Custom Menu Shortcode function to a Shortcode.
*
*/
add_shortcode( "custommenu", "custom_menu_shortcode" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment