WordPress.org

Ready to get started?Download WordPress

Forums

filtering certain specific tags (3 posts)

  1. gmorehoudh
    Member
    Posted 5 years ago #

    I'm trying to filter a certain tag so that users can't see it when they read my blog. It's to be used for internal purposes. However, this code isn't working:

    function hide_noaff_tag($tag) {
    	if($tag === "noaff") {
    		return null;
    	} else {
    		return "lol" . $tag;
    	}
    }

    [...]

    add_filter('the_tags', 'hide_noaff_tag');

    Note the 'lol' test there -- the tags aren't even displaying with the lol prepended. What am I doing wrong?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    I know, the tag filters are mucked up. Anyway, you're using them wrong even if they were correct.

    add_filter('term_links-post_tag','hide_noaff_tag');
    function hide_noaff_tag($tags) {
    	$ret = array();
    	foreach ($tags as $tag) {
    		if (strpos($tag,'noaff') === false) {
    			$ret[]=$tag;
    		}
    	}
    	return $ret;
    }

    Try something more like that.

  3. gmorehoudh
    Member
    Posted 5 years ago #

    Once again, thanks for your help. :) It seems the documentation is a little dated. :/

Topic Closed

This topic has been closed to new replies.

About this Topic