Does anyone know how to exclude/filter a tag from the HTML string generated by get_the_tag_list()?
http://codex.wordpress.org/Function_Reference/get_the_tag_list
Any help much appreciated.
3 Answers
function mytheme_filter_tags( $term_links ) {
$result = array();
$exclude_tags = array( 'some tag', 'another tag', 'third tag' );
foreach ( $term_links as $link ) {
foreach ( $exclude_tags as $tag ) {
if ( stripos( $link, $tag ) !== false ) continue 2;
}
$result[] = $link;
}
return $result;
}
add_filter( "term_links-post_tag", 'mytheme_filter_tags', 100, 1 );
// do loop stuff
echo get_the_tag_list('<p>Tags: ',', ','</p>');
// end loop stuff
remove_filter( "term_links-post_tag", 'mytheme_filter_tags', 100 );