Advertisement
arie_cristianD

only show related categories on category page

Oct 16th, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. function filter_widget_categories_args( $args ) {
  2.     if ( is_category() ) {
  3.         $current_category = get_queried_object();
  4.         if ( $current_category && ! is_wp_error( $current_category ) ) {
  5.             $args['child_of'] = 0 !== $current_category->category_parent ? $current_category->category_parent : $current_category->term_id;
  6.  
  7.             if ( empty( get_categories( $args ) ) ) {
  8.                 unset( $args['child_of'] );
  9.             }
  10.         }
  11.     }
  12.     return $args;
  13. }
  14. add_filter( 'widget_categories_args', 'filter_widget_categories_args' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement