• I’m trying to add a wordpress menu to my wordpress theme and when I follow the specified instructions online, it doesn’t work.

    I have this in functions.php

    <?php
    
    function register_my_menus() {
      register_nav_menus(
        array(
          'header-menu' => __( 'Header Menu' ),
          'sidebar-menu' => __( 'Sidebar Menu' )
         )
       );
     }
     add_action( 'init', 'register_my_menus' );

    In sidebar.php of my theme theme I have this code

           <?php
            wp_nav_menu(
              array(
                'theme_location' => 'sidebar-menu',
                'container_class' => 'sidebar'
              )
            ); 
            ?>

    But when I inspect the HTML code that is outputted, my meny doesn’t have the sidebar class on it, instead it is given a menu class.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The menu itself will have a menu class on it. The default class for the container is 'menu-{menu slug}-container', but for your code, it should be a <div> with a class of sidebar.

    https://developer.www.ads-software.com/reference/functions/wp_nav_menu/

    Moderator bcworkz

    (@bcworkz)

    There’s nothing wrong with your code. If you are not seeing expected results, either you’re seeing stale data due to caching, or some other code is confounding your attempt. Or your expectation is not aligned with what constitutes a “container class”. It’s the <div> under <nav> but above the outermost <ul> element.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘container_class isn’t being applied for wp_nav_menu’ is closed to new replies.