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.

I have created a parent theme with a nav menu walker that works fine. I want to create a child theme to show small variations to the client. When I put the same code in the child theme it doesn't work.

The code in the header of both my parent and child theme:

$dt_menu_walker = new Dt_Main_Walker_Nav_Menu();

$navmenu_args = array(
    'theme_location' => 'header-menu',
    'container_class' => 'col-md-12',
    'menu_class' => 'menu-clearfix',
    'link_before' => '<span>',
    'link_after' => '</span>',
    'walker' => $dt_menu_walker,
    'depth' => 2
);

wp_nav_menu( $navmenu_args );

With the child theme I get this repeated:

Notice: Trying to get property of non-object in S:\hdt.co.uk\public_html\wp-includes\nav-menu-template.php on line 153

Notice: Trying to get property of non-object in S:\hdt.co.uk\public_html\wp-includes\nav-menu-template.php on line 156

Notice: Trying to get property of non-object in S:\hdt.co.uk\public_html\wp-includes\nav-menu-template.php on line 156

Notice: Trying to get property of non-object in S:\hdt.co.uk\public_html\wp-includes\nav-menu-template.php on line 158

then a list of empty bullet points

<div class="menu-clearfix">
    <ul>
        <li id="menu-item-5" class="menu-item-5"><a></a></li>
        <li id="menu-item-312" class="menu-item-312"><a></a></li>...

I have checked:

  • $dt_menu_walker IS being created correctly
  • If I change 'walker' => $dt_menu_walker, to 'walker' => '', the menu is displayed
  • If I define and use a new custom walker in the child theme, the same thing occurs

The offending lines in nav-menu-template.php are:

$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
/** This filter is documented in wp-includes/post-template.php */
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;

If I add a var_dump($args) before that I can see that using my parent theme $args is an object, but using my child theme $args is an array. I tried changing the lines to

$item_output = $args['before'];
$item_output .= '<a'. $attributes .'>';
/** This filter is documented in wp-includes/post-template.php */
$item_output .= $args['link_before'] . apply_filters( 'the_title', $item->title, $item->ID ) . $args['link_after'];
$item_output .= '</a>';
$item_output .= $args['after'];

which got rid of the error but no menu appears.

So, any idea why I can't use a custom nav walker in my child theme?

share|improve this question
    
Ah - I found the problem. It was the theme location. At some point I'd changed the name of the theme location from 'header-menu' to 'header-menu-primary', but never unregistered 'header-menu'. That's why it worked in my parent theme, but I guess as the child theme was new, it didn't have the old theme location. –  ellcub Apr 25 at 16:25

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.