Skip to content

Instantly share code, notes, and snippets.

@oneblackcrayon
Created February 25, 2016 04:48
Show Gist options
  • Save oneblackcrayon/0da95142bae0cba20eb9 to your computer and use it in GitHub Desktop.
Save oneblackcrayon/0da95142bae0cba20eb9 to your computer and use it in GitHub Desktop.
Menus in a shortcode
<?php
Author URI: http://www.basvanderlans.nl
*/
/**
* Adds the possibility to callback Custom Menus by a Shortcode
*
* @author Bas van der Lans
* @copyright based on a snippet by Cozmoslabs: http://www.cozmoslabs.com/1170-wp_nav_menu-shortcode/
* @link http://www.basvanderlans.nl/wordpress-custom-menu-shortcode
* @param array $atts WordPress Custom Menu Parameters
* @return string w/ WordPress Custom Menu
*/
// Menus in a shortcode
function vo_custom_menu_shortcode( $atts, $content = null ) {
extract( shortcode_atts(
array(
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => '',
'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", "vo_custom_menu_shortcode" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment