I’m building a theme on top of a starter theme (wp-bootstrap) and am having trouble getting the Nav Walker to show the current menu item. current-menu-item is not there when I use a web inspector on the output html. So therefore I can’t style it.
This is the code in my template file:
<?php
/** Loading WordPress Custom Menu **/
wp_nav_menu( array(
'menu' => 'main-menu',
'container' => '',
'container_class' => 'navbar-blue',
'menu_class' => 'nav',
'menu_id' => 'main-menu',
'walker' => new Bootstrapwp_Walker_Nav_Menu()
) ); ?>
And this is the code in function.php:
include 'includes/class-bootstrapwp_walker_nav_menu.php';
And finally this is the code from the customer nav walker file:
class Bootstrapwp_Walker_Nav_Menu extends Walker_Nav_Menu {
function __construct() {
}
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"dropdown-menu\">\n";
}
}
I’ve looked over a few stackexchange answers and tried changing the code to match them, but nothing has solved the issue (ie: nothing has made current-menu-item appear in the html output).
Any help would be appreciated.
1 Answer
Since it is working as you expect in the header.php
file (but not in sidebar.php
),
you could add this into header.php
:
global $my_nav;
$my_nav= wp_nav_menu( array(
'menu' => 'main-menu',
'container' => '',
'container_class' => 'navbar-blue',
'menu_class' => 'nav',
'menu_id' => 'main-menu',
'walker' => new Bootstrapwp_Walker_Nav_Menu(),
'echo' => 0,
) ); ?>
and then in your sidebar.php
file you could add
global $my_nav;
echo $my_nav;
to display the menu.