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.

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

1 Answer
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="https://wordpress.stackexchange.com/questions/138827/.get_tag_link($tag->term_id)." >'.$tag->name . '</a> '; 
        }
    } else {
         echo '<a href="https://wordpress.stackexchange.com/questions/138827/.get_tag_link($tag->term_id).">'.$tag->name . '</a> '; 
    }
  }
}
}
add_filter('the_tags', 'myTags');

Leave a Reply

Your email address will not be published. Required fields are marked *