I am trying to manually add two items to my menu because I want them to be (linked) images, and I don't believe there's a way to do that without some custom code. Going off the instructions in This answer, since my case was a little different, I added the following code to my functions.php file:
class Custom_Walker_Nav_Menu extends Walker_Nav_Menu {
function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
$output .= $indent . '<li>';
$output .= 'Testing';
$output .= "</li>\n";
$output .= $indent . '<li>';
$output .= 'Testing';
$output .= "</li>\n";
$output .= "$indent</ul>\n";
}
}
I thought that would print out all of the real menu items, then append the two "Testing"s to the end before the </ul>. In my header.php file, I altered the wp_nav_menu call to:
<?php wp_nav_menu( array(
'theme_location' => 'primary',
'depth' => 3,
'walker' => new Custom_Walker_Nav_Menu() )
); ?>
I also tried removing () from 'walker' => new Custom_Walker_Nav_Menu() because I saw that suggested both ways in various threads here.
No matter what I do, though, the site never implements my "Testing" placeholders. I think the problem is that I'm placing something in the wrong place in my file system or naming something incorrectly, because what I'm seeing whenever I try this is just the normal nav menu output. I've double-checked, though, and I am editing the header.php and functions.php files inside my custom theme. Does anyone have an idea where I'm going wrong?
Aucun commentaire:
Enregistrer un commentaire