0

I try to add container for of main navigation menu. This is entire functions.php of my custom theme:

<?php

function gzabrze_menu() {
    register_nav_menu('glowne',__( 'Menu Główne' ));
}
add_action( 'init', 'gzabrze_menu' );

class Child_Wrap extends Walker_Nav_Menu {
    function start_lvl(&$output, $depth = 0, $args = array())
    {
        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent<div class=\"custom-sub\"><ul class=\"bg-dark\">\n";
    }
    function end_lvl(&$output, $depth = 0, $args = array())
    {
        $indent = str_repeat("\t", $depth);
        $output .= "$indent</ul></div>\n";
    }
}

?>

Now in my header.php i use code below to print main navigation on my site:

<?php 
    wp_nav_menu( array( 
        'walker'            => new Child_Wrap(),
        'theme_location'    => 'glowne',
        'container'         => 'nav',
        'container_id'      => 'main-menu',
        'menu_class'        => "nav-menu",
        'items_wrap'        => '<ul>%3$s</ul>',
    ) ); 
?>

Problem is that the my <ul class="sub-menu"> which now should be <ul class=\"bg-dark\"> instead, is still without container which should appear after use new Child_Wrap() from above.

It seems that my theme does not include Child_Wrap class from functions.php code.

I use Wordpress 4.4.2 .

  • Are you sure you've emptied all caches? – Max Yudin Apr 8 '16 at 16:50
  • You mean browser cache? If other, how can i do that? – X9DESIGN Apr 8 '16 at 17:26
  • This is not the source of the problem. I try to use this on other theme, and also not work. Even when i edit nav-menu-template.php in wp-includes folder, nothing is changing. – X9DESIGN Apr 8 '16 at 17:43
  • I mean caching plugins like W3 Super Cache or similar to. – Max Yudin Apr 9 '16 at 10:46
  • Yes, I did that. But i find what was wrong. I delete some plugins (Unyson Framework, Jetpack) and now class take action. When i install this plugins first, and then add class to my functions.php nothing was changing. Then in other WP installation i add this class first and plugins second, all wroks fine. When on the first WP installation i just remove plugins above, suddenly all starts works fine. – X9DESIGN Apr 9 '16 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.