Advertisement
arie_cristianD

add active class in single post

Aug 4th, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.41 KB | None | 0 0
  1. function add_active_class_to_category_menu( $classes, $item ) {
  2.     if ( is_single() ) {
  3.         $current_category = jnews_get_primary_category( get_the_ID() );
  4.         if ( $current_category ) {
  5.             if ( $item->object_id == $current_category && $item->object == 'category' ) {
  6.                 $classes[] = 'current-menu-item';
  7.             }
  8.         }
  9.     }
  10.     return $classes;
  11. }
  12. add_filter( 'nav_menu_css_class', 'add_active_class_to_category_menu', 10, 2 );
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement