Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function exclude_parent_categories( $args ) {
- $args['exclude'] = get_parent_categories();
- return $args;
- }
- function get_parent_categories() {
- $parents = array();
- $categories = get_categories( array( 'hide_empty' => false ) );
- foreach ( $categories as $category ) {
- if ( $category->parent !== 0 ) {
- $parents[] = $category->parent;
- }
- }
- return implode( ',', $parents );
- }
- add_filter( 'widget_categories_args', 'exclude_parent_categories' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement