Enter your keyword

Wordpress Menu

Custom Shortcode For Call WordPress Menu

function menu($atts, $content = null)
    {
        extract(shortcode_atts(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' => '',
                'depth' => 0,
                'walker' => ''
        ) , $atts));
        return wp_nav_menu(array(
                'theme_location' => $theme_location,
                '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
        ));
    }
// Create the shortcode 
add_shortcode("menu", "menu");
[menu menu=Top Navigation menu_class=main_menu]  // Here "Top Navigation" is Menu Name

How to Get Custom Menu Items

add_filter('wp_nav_menu_items', 'wp_nav_menu_custom', 10, 2);
function wp_nav_menu_custom($items, $args) {
if( $args->theme_location == 'primary' ) {

$menu_name = 'primary';
$locations = get_nav_menu_locations();
//echo '<pre/>'; print_r($locations); die;
$menu = wp_get_nav_menu_object(4, $menu_name );
$menuitems = wp_get_nav_menu_items( $menu->term_id , array( 'order' => 'DESC' ) );

foreach ( $menuitems as $item ){

$id = get_post_meta( $item->ID,'_menu_item_object_id', true );
echo '<br/>';
echo $id;
//$page = get_page( $id );
//$link = get_page_link( $id );
}

}
}