Skip to main content
added 142 characters in body
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

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!

EDIT

I do not wish to modify the original get_the_tags using filters in function.php as I display all tags at other places of the website

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!

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?

EDIT

I do not wish to modify the original get_the_tags using filters in function.php as I display all tags at other places of the website

added 93 characters in body
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

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!

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!

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!

Source Link

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!