Filtering Only a Specific Menu using the “add_additional_class_in_li”?

Question

Thanks to some help on here, I’ve managed to add bootstrap classes in main navigation li tag by adding this to my theme’s functions.php

// adding css to li  tags for menu styling

function add_additional_class_in_li($classes, $item, $args) {
    if(isset($args->add_li_class)) {
        $classes[] = $args->add_li_class;
    }
    return $classes;
}
add_filter('nav_menu_css_class', 'add_additional_class_in_li', 1, 3);
function add_additional_class_in_ancher($atts) {
  $atts['class'] = "nav-link p-lg-4 text-warning";
  return $atts;
}
add_filter( 'nav_menu_link_attributes', 'add_additional_class_in_ancher');

and I am calling this menu in navigation.php by:

<div class="collapse fixed-top justify-content-center navbar-collapse position-relative sticky-top text-warning w-100" id="navbarToggler2">
                    <?php
 wp_nav_menu(
        array(
        'menu'                 => 'header-menu',
        'container'            => 'ul',
        'container_class'      => '',
        'menu_class'           => 'navbar-nav',
        'theme_location'       => 'header-menu',
        'menu_id'              => 'header-menu',
        'add_li_class'         => 'nav-item',
        'echo'                 => true,
    )
    ); ?>   
</div>

However, I’ve now added another 3 menus to put in the footer and now I want different bootstrap for li class link-light to be applied to these 3 footers(same for all 3) (by default same li classes nav-link p-lg-4 text-warning are applying to all)

My code for registering the menus is:

function registering_menus() {
  register_nav_menus(
    array(
      'header-menu' => __( 'Header_menu' ),             //header nav
      'footer-menu-1' => __( 'Footer menu 1' ),
      'footer-menu-2' => __( 'Footer menu 2' ),
      'footer-menu-3' => __( 'Footer menu 3' ),
      'footer-menu-4' => __( 'Footer menu 4' )
    )
  );
}
add_action( 'init', 'registering_menus' );

and i am calling these 3 menu’s in footer like this (showing only 1):

<div class="col-sm-4 col-xl-2 py-3"> 
                        <h2 class="fw-bold h5 mb-4 text-info text-uppercase">Quick links</h2>
                                            <?php
 wp_nav_menu(
        array(
        'menu'                 => 'footer menu 1',
        'container'            => 'ul',
        'container_class'      => '',
        'menu_class'           => 'list-unstyled',
        'theme_location'       => 'footer-menu-1',
        'add_li_class'         => 'mb-3',
        'echo'                 => true,
    )
    ); ?>   
</div>

what can I do to solve this ?

0
Chandresh Tiwari 2 months 2021-07-31T03:35:45-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse