WordPress.org

Support

Support » Plugins and Hacks » filtering certain specific tags

filtering certain specific tags

  • gmorehoudh

    @gmorehoudh

    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    @otto42

    WordPress.org Tech Dude

    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.

    gmorehoudh

    @gmorehoudh

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘filtering certain specific tags’ is closed to new replies.