Skip to main content
2 of 3
added 93 characters in body
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

Include tags from array, ignore the rest in get_the_tags

I'm trying to exclude a large amount of tags from being displayed in get_the_tags function. I have successfully excluded tags using this code:

<?php 
    $links = array(); 
    foreach (get_the_tags() as $this_tag) { 
        if ($this_tag->name != "test1" && $this_tag->name != "test2"){ 
            $links[] = '<a href="'.get_tag_link($this_tag->term_id).'" title="'.$this_tag->name.'">'.$this_tag->name.'</a>'; 
        } 
    } 
    echo implode(' • ', $links);
?>

However, the issue is there's new tags added regularly, and having to manually modify the exclude code isn't something i want to do, can i somehow specify an array of tags to INCLUDE and then automatically exclude every other tag from being displayed?

Any ideas how i could solve this? Thanks!