WordPress.org

Ready to get started?Download WordPress

Forums

add_filter('the_tags', 'myTags'); (4 posts)

  1. DenisCGN
    Member
    Posted 1 year ago #

    Hi,

    I try to strip the following "tag" ---> featured

    <?php
    function myTags($customTags) {
    $customTags = str_replace ('featured', '', $customTags);
    return $customTags;
    }
    add_filter('the_tags', 'myTags');
    ?>

    This works well, but left a COMMA. When I try to strip "featured," nothing happens :-(

    Please can someone help,
    Cheers,
    Denis

  2. bcworkz
    Member
    Posted 1 year ago #

    The filter you hooked passes an html list of tags. There is the html close anchor tag '' between 'featured' and the comma, that is why 'featured,' doesn't work. If you searched for 'featured,' and replaced back in '' it would probably work.

    If you look at your served page source, you will see anchor tags with broken hrefs and no link text. While this works OK, it is a bit sloppy. Just sayin' ;)

  3. DenisCGN
    Member
    Posted 1 year ago #

    Thanks for the answer.
    Will there be another filter to exclude the tag "featured"?

  4. bcworkz
    Member
    Posted 1 year ago #

    I really doubt it, the code just grabs tags, it doesn't examine what they are.

    I neglected to wrap my html examples in backticks in my previous reply, so they got stripped out, my intent was the text you are trying to extract the 'featured,' from actually looks like this:
    featured</a>,
    You need to search for the whole thing and replace back the closing tag.

Topic Closed

This topic has been closed to new replies.

About this Topic