Skip to content

Instantly share code, notes, and snippets.

@asufian97
Last active November 18, 2022 08:06
Show Gist options
  • Save asufian97/55cd9deb6bc828ef85dbd626431a9212 to your computer and use it in GitHub Desktop.
Save asufian97/55cd9deb6bc828ef85dbd626431a9212 to your computer and use it in GitHub Desktop.
wordpress nav menu li add class and li >a>active class
/add li class
function atg_menu_classes($classes, $item, $args) {
if($args->theme_location == 'wpj-main-menu') {
$classes[] = 'hvr-bounce-to-bottom';
}
return $classes;
}
add_filter('nav_menu_css_class','atg_menu_classes',1,3);
//li a add class
function add_link_atts($atts) {
$atts['class'] = "nav-item-child nav-item-hover";
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'add_link_atts');
//add active class
add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
function special_nav_class ($classes, $item) {
if (in_array('current-menu-item', $classes) ){
$classes[] = 'active ';
}
return $classes;
}
@KasunWijesekara
Copy link

Thank you for this :)

@asufian97
Copy link
Author

you are welcome ;)

@GreencrisMessi
Copy link

GreencrisMessi commented Nov 18, 2022

Hey bro!! I want to set active menu when click page detail or category website, I how to itt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment