Web Designing in jaipur{ menu}

Showing posts with label wp_nav_menu shortcode. Show all posts
Showing posts with label wp_nav_menu shortcode. Show all posts

Monday, 4 April 2016

How to Build WordPress Navigation Using wp_nav_menu()

<?php
$defaults = array(
 'theme_location'  => '',
 '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'      => '',
 'items_wrap'      => '&lt;ul id="%1$s" class="%2$s">%3$s&lt;/ul>',
 'depth'           => 0,
 'walker'          => ''
);
 
wp_nav_menu( $defaults );
?>

wp_nav_menu shortcode

wp_nav_menu shortcode

To install the shortcode just place this code inside functions.php file of your theme.
// Function that will return our Wordpress menu
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");