Skip to content

Instantly share code, notes, and snippets.

@chaance
Last active March 23, 2018 17:46
Show Gist options
  • Save chaance/8010f15d83b618c05e154bc467a02e93 to your computer and use it in GitHub Desktop.
Save chaance/8010f15d83b618c05e154bc467a02e93 to your computer and use it in GitHub Desktop.
WordPress function to exclude `Uncategorized` category from all terms lists.
<?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