Last active
March 23, 2018 17:46
-
-
Save chaance/8010f15d83b618c05e154bc467a02e93 to your computer and use it in GitHub Desktop.
WordPress function to exclude `Uncategorized` category from all terms lists.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Exclude `Uncategorized` category from all terms lists. | |
* | |
* @param array $terms Array of taxonomy terms. | |
* @return array List of terms, less 1 | |
*/ | |
function xx_exclude_terms_uncategorized( $terms ) { | |
$exclude_terms = [ 1 ]; // Exclude `Uncategorized` category | |
if ( ! empty( $terms ) && is_array( $terms ) ) { | |
foreach ( $terms as $key => $term ) { | |
if ( in_array( $term->term_id, $exclude_terms ) ) { | |
unset( $terms[$key] ); | |
} | |
} | |
} | |
return $terms; | |
} | |
add_filter( 'get_the_terms', 'xx_exclude_terms_uncategorized' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment