How to change li classes in wp_nav_menu open

How to change li classes in wp_nav_menu

With the standard output of the wp_nav_menu function, menu items are displayed as a list of li with certain standard WordPress classes, so to change these classes use the function below:

<?php 

wp_nav_menu(
    array(
        'theme_location' => 'header_nav',
        'menu_class' => 'mymenuclass',
        'add_li_class' => 'nav-class'
),
)

 ?>

in function.php

<?php 

function changeclass($classes, $item, $args){
if(isset($args->add_li_class)){
    $classes[] = $args->add_li_class;
}
return $classes;
}

add_filter('nav_menu_css_class', 'changeclass', 1, 3);

?>
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation