Make specific tag visible only to logged in users in front-end

I have this specific tag I need to assign to my posts but I need to hide it from regular visitors so that only logged in people can see it. How do I go about it? What WordPress function/hook should I be looking into?

I know that I could use is_user_logged_in() and I am also looking into is_tag(), but how do I put this together? Currently I’m having it displayed in my single template with the_tags(), but it doesn’t seem to offer a parameter to exclude a particular tag.

Read More

Pseudo code would be: if user is logged in then show all tags except a specific tag.

Related posts

Leave a Reply

1 comment

  1. Add the add_filter to your theme’s functions.php file

    function myTags() {
    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
          if($tag->slug=='your specific tag slug'){
            if(is_user_logged_in() ) {
        echo '<a href='.get_tag_link($tag->term_id).' >'.$tag->name . '</a> '; 
            }
        } else {
             echo '<a href='.get_tag_link($tag->term_id).'>'.$tag->name . '</a> '; 
        }
      }
    }
    }
    add_filter('the_tags', 'myTags');