Created
April 5, 2022 01:18
-
-
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.
This file contains hidden or 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 | |
/** | |
* 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