Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Using the following, or any other custom Walker_Nav_Menu seems to cause a blank navigation menu, I tried specifying the default to make sure I wasn't going crazy yet it still blanks the output... Any ideas on what is going wrong?

<?php wp_nav_menu( array( 'theme_location' => 'primary', 'depth' => 3, 'walker' => new Walker_Nav_Menu() ) ); ?>

In Context

<?php
/**
 * The Header for our theme.
 *
 * Displays all of the <head> section and everything up till <div id="main">
 *
 * @package Expound
 */
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<![endif]-->

<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<div id="page" class="hfeed site">
    <?php do_action( 'expound_header_before' ); ?>
    <header id="masthead" class="site-header" role="banner">
        <div class="site-branding">
            <div class="site-title-group">
                <a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
                    <!--div class="site-title"><!--?php bloginfo( 'name' ); ?></div-->
                    <img height="240" width="722" alt="The All Australian Minecraft Community" class="wp-post-image" src="http://taamc.com/wordpress/wp-content/themes/expound-child/images/logo.png">
                    <!--h2 class="site-description"--><!--?php bloginfo( 'description' ); ?--><!--/h2-->
                    <!--div id="sub-title">
                        <div id="sub-title-image"></div>
                    </div-->
                </a>
            </div>
        </div>
        <div class = "site-title-group">
                <?php if ( dynamic_sidebar('header_widget_area') ) : else : endif; ?>
        </div>
        <nav id="site-navigation" class="navigation-main" role="navigation">
            <h1 class="menu-toggle"><?php _e( 'Menu', 'expound' ); ?></h1>
            <div class="screen-reader-text skip-link"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'expound' ); ?>"><?php _e( 'Skip to content', 'expound' ); ?></a></div>
####################################################################################    
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'depth' => 3, 'walker' => new Walker_Nav_Menu()) ); ?>
####################################################################################
            <div class="site-nav-search"><?php if ( dynamic_sidebar('navigation_widget_area') ) : else : endif; ?></div>
            <?php do_action( 'expound_navigation_after' ); ?>
        </nav><!-- #site-navigation -->
    </header><!-- #masthead -->
    <?php do_action( 'expound_header_after' ); ?>

    <div id="main" class="site-main">

The above is currently in my header.php of a child theme if that makes any difference, and the original theme also used the default walker, however it wasn't explicitly stated.

with php as above

        <div class="menu">
            <ul class=" nav-menu">
            <li class="current_page_item">
                <a href="http://taamc.com/">Home</a>
            </li>
            <li id="menu-item-21" class="menu-item-21">
                <a></a>
            </li>
            <li id="menu-item-87" class="menu-item-87">
                <a></a>
            </li>
            <li id="menu-item-122" class="menu-item-122">
                <a></a>
            </li>
            <li id="menu-item-28" class="menu-item-28">
                <a></a>
            </li>
            <li id="menu-item-127" class="menu-item-127">
                <a></a>
            </li>
            <li id="menu-item-22" class="menu-item-22">
                <a></a>
            </li>
        </ul>
    </div>

Gives errors:

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 148

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 153

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 148

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 153

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 148

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 153

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 148

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 153

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 148

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 153

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 148

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 151

Notice: Trying to get property of non-object in /home/taamc/public_html/wordpress/wp-includes/nav-menu-template.php on line 153

with php as found by default in the theme

<?php wp_nav_menu( array( 'theme_location' => 'primary', 'depth' => 3) ); ?>

<div class="menu">
    <ul class=" nav-menu">
    <li class="current_page_item">
        <a href="http://taamc.com/">Home</a>
    </li>
    <li class="page_item page-item-21">
        <a href="http://taamc.com/activity/">Activity</a>
    </li>
    <li class="page_item page-item-87">
        <a href="http://taamc.com/gallery/">Gallery</a>
    </li>
    <li class="page_item page-item-122">
        <a href="http://taamc.com/getting-started/">Getting Started</a>
    </li>
    <li class="page_item page-item-28">
        <a href="http://taamc.com/groups/">Groups</a>
    </li>
    <li class="page_item page-item-127">
        <a href="http://taamc.com/map/">Map</a>
    </li>
    <li class="page_item page-item-22">
        <a href="http://taamc.com/members/">Members</a>
    </li>
    </ul>
</div>
share|improve this question
    
Please post the code in context and provide debugging information. –  s_ha_dum Feb 8 at 19:23
    
Added context and new notices that appeared when using debugging. –  Ryan The Leach Feb 8 at 20:09
    
Can you please add the Code for your custom walker? The Error seems to be in there. –  fischi Feb 8 at 20:36
    
It isn't a custom walker, as far as I know it is the default wordpress walker, just explicitly stated. –  Ryan The Leach Feb 8 at 20:37
1  
All your errors seem to be about $args not being object inside of the walker. I would look for filter that messes up arguments for some reason, this does look like it should work. –  Rarst Feb 8 at 21:54
show 1 more comment

4 Answers 4

You should pass an actual object as 'walker' - not create one on the fly. The correct way to do it is:

$myWalker = new Walker_Nav_Menu();
wp_nav_menu( array( 'theme_location' => 'primary', 'depth' => 3, 'walker' => $myWalker ) ); ?>

Also make sure you extend Walker_Nav_Menu in your custom class.

share|improve this answer
    
How is this any different? –  Ryan The Leach Feb 10 at 3:06
add comment

do you use walker menu for mobile responsive purpose ? If yes then you can go for an another solution.(Only if you cant fix your errors with the walker menu)

you can hide main menu on mobile devices and can use another one. here is an example

<div class="m-sec-nav">
        <?php 
        $menu_name = 'careers-menu'; //your menu theme_location
        if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
                $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
                $menu_items = wp_get_nav_menu_items($menu->term_id); ?>
                    <select onchange="location = this.options[this.selectedIndex].value;">
                    <?php foreach ( (array) $menu_items as $key => $menu_item ) { ?>
                        <option value="<?php echo $menu_item->url; ?>"><?php echo $menu_item->title; ?></option>
                    <?php } ?>
                    </select>
                <?php } ?>

    </div>
share|improve this answer
    
I've already worked around the original issue, however none of it would count as an answer to the question I've asked so I've not answered my own question, I suspect that it may be a filter of some kind gone rogue. –  Ryan The Leach Feb 12 at 4:42
add comment

You need to make sure your menu is properly registered in your functions.php and then activated in the WP Dashboard.

add_action( 'init', register_nav_menu( 'navigation', __( 'Navigation' ) ) );

Otherwise I was just facing a long list of empty bullet points.

http://codex.wordpress.org/Navigation_Menus

share|improve this answer
add comment

I think the wholee problem is your trying to use the default walker, but by declaring it in the walker field your telling wordpress your trying to load a custom walker, the wp walker is loaded by default if left empty.

two options:

1/ change 'walker' => new Walker_Nav_Menu() to 'walker' => '' as its called by default.

2/ edit declaration to a new name like: new themeslug_Walker_Nav_Menu() then add the following to your function.php:


class themeslug_walker_nav_menu extends Walker_Nav_Menu {

// add classes to ul sub-menus
    function start_lvl( &$output, $depth ) {
        // depth dependent classes
        $indent = ( $depth > 0  ? str_repeat( "\t", $depth ) : '' ); // code indent
        $display_depth = ( $depth + 1); // because it counts the first submenu as 0
        $classes = array(
            'sub-menu',
            ( $display_depth % 2  ? 'menu-odd' : 'menu-even' ),
            ( $display_depth >=2 ? 'sub-sub-menu' : '' ),
            'menu-depth-' . $display_depth
            );
        $class_names = implode( ' ', $classes );

        // build html
        $output .= "\n" . $indent . '' . "\n";
    }

    // add main/sub classes to li's and links
     function start_el( &$output, $item, $depth, $args ) {
        global $wp_query;
        $indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent

        // depth dependent classes
        $depth_classes = array(
            ( $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ),
            ( $depth >=2 ? 'sub-sub-menu-item' : '' ),
            ( $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ),
            'menu-item-depth-' . $depth
        );
        $depth_class_names = esc_attr( implode( ' ', $depth_classes ) );

        // passed classes
        $classes = empty( $item->classes ) ? array() : (array) $item->classes;
        $class_names = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ) );

        // build html
        $output .= $indent . 'ID . '" class="' . $depth_class_names . ' ' . $class_names . '">';

        // link attributes
        $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
        $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
        $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
        $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
        $attributes .= ' class="menu-link ' . ( $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ) . '"';

        $item_output = sprintf( '%1$s%3$s%4$s%5$s%6$s',
            $args->before,
            $attributes,
            $args->link_before,
            apply_filters( 'the_title', $item->title, $item->ID ),
            $args->link_after,
            $args->after
        );

        // build html
        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
    }
}

see the codex its explains quite well.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.