Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created April 5, 2022 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/1cd9a08d4a6974c38ef92be271fe7e45 to your computer and use it in GitHub Desktop.
Save kimcoleman/1cd9a08d4a6974c38ef92be271fe7e45 to your computer and use it in GitHub Desktop.
Hide tags from display if there is only one post in the taxonomy.
<?php
/**
* Hide tags from display if there is only one post in the taxonomy.
*
*/
function my_get_the_terms( $terms, $post_id, $taxonomy ) {
if ( $taxonomy === 'post_tag' ) {
foreach( $terms as $key => $term ) {
if ( $term->count < 2 ) {
unset( $terms[ $key ] );
}
}
}
return $terms;
}
add_filter( 'get_the_terms', 'my_get_the_terms', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment