WordPress Plugin Submenu Shortcode
<?php
/**
* @package Submenu Shortcode
* @version 1.0
*/
/*
Plugin Name: Submenu Shortcode
Plugin URI: https://gist.github.com/5813043
Description: Add Submenu with a shortcode: [submenu menu="Menu" level=2]. A plugin based on a script by <a href="http://www.cozmoslabs.com/1170-wp_nav_menu-shortcode/">Cozmoslabs</a>. Dependency on <a href="http://wordpress.org/plugins/codepress-menu">Codepress Menu</a>.
Author: Josef Jezek
Author URI: http://about.me/josefjezek
Version: 1.0
*/
/**
* Adds the possibility to callback Submenu 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 Submenu Parameters
* @return string w/ WordPress Submenu
*/
function submenu_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' => '',
'level' => 0
), $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,
'level' => $level
)
);
}
/**
* Adds the Submenu Shortcode function to a Shortcode.
*/
add_shortcode( "submenu", "submenu_shortcode" );
?>