How to list all tags except the current tag in tag.php
Question
I'm struggling to find a way to list all my tags without the current tag showing when i'm on a tag.php page. All I have is this, but it's not the current tag?
Solution
You may try get_tags
with exclude
parameter.
https://codex.wordpress.org/Function_Reference/get_tags
get_queried_object_id
get the tag ID from tag page.
$tags = get_tags(array(
'exclude' => get_queried_object_id(),
));
$tagList = array();
foreach($tags as $tag)
{
$tagList[] = '<a href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a>';
}
echo implode(', ', $tagList);
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange