daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Jan 13th, 2018 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. \\add custom class into <ul> tag
  2. function atg_menu_classes($classes, $item, $args) {
  3.   if($args->theme_location == 'header_menu') {
  4.     $classes[] = 'nav-item';
  5.   }
  6.   return $classes;
  7. }
  8. add_filter('nav_menu_css_class','atg_menu_classes',1,3);
  9.  
  10. //add custom class into <ul><li><a> means a tag
  11. add_filter( 'nav_menu_link_attributes', 'wpse156165_menu_add_class', 10, 3 );
  12.  
  13. function wpse156165_menu_add_class( $atts, $item, $args ) {
  14.     $class = 'nav-link'; // or something based on $item
  15.     $atts['class'] = $class;
  16.     return $atts;
  17. }
  18.  
  19. //add custom class to active page
  20. add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
  21. function special_nav_class ($classes, $item) {
  22.     if (in_array('current-page-ancestor', $classes) || in_array('current-menu-item', $classes) ){
  23.         $classes[] = 'active ';
  24.     }
  25.     return $classes;
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top