How can exclude some tags from 'the_tags' list? (5 posts)

  1. snoogly
    Posted 8 years ago #

    I want to use 'the_tags' to generate a list of a post's tags, but I need to exclude certain tags from the list.

    How do I do this? I have hunted in the Codex, but can't find a way to exclude tags.

  2. quirksmode
    Posted 8 years ago #

    I am having the same problem, did you ever solve this?

  3. Jesse Heap
    Posted 8 years ago #

    I think this is what you are looking for:

    Excluding Tags from Posts in WordPress

  4. Or you could add a filter and filter them out entirely...

    function exclude_tags($tags) {
    foreach ($tags as $tag)
    switch ($tag->name) {
     case 'exclude-this-tag':
     case 'exclude-this-tag-too':
      $newtags[] = $tag;
    return $newtags;
    add_filter( 'get_the_tags', 'exclude_tags');
  5. Dunkkan
    Posted 7 years ago #

    You guys you'r da mastas'

    Could I modify the Otto's code (Otto, if reading, how do I modify your code) to exclude, not a compact tag, but an expresion foundable in a tag ?

    Let's say I have a tag : Lions in The Circus.

    And : Birds in The Circus.

    And I need to exclude every tag where the 'Circus' expression is present.

    I know the first solution allows that, but it serves to print a conventional list of tags, when my intention is use the filtered query for another purpose (a customized related posts plugin).

    With a generic function I could get it.
    It must be out there some magical bit of code, some !empty function, or switch, or any of this magical php words which can work it out.

    So please, let's awake this threat :)


Topic Closed

This topic has been closed to new replies.

About this Topic