0

I want to display a particular message when a post has a specific tag on the article.

I've done this, however the 'Hello' text is being shown no matter if the post has the tag 'test' or not.

<?php if ( has_tag() == 'test' ) : ?>

    Hello

<?php endif; ?>
1
  • You're using has_tag wrong. You should be attempting has_tag('test') in your if. – Greg McMullen Jan 22 '18 at 14:35
2

According to the docs the input parameters can be:

has_tag( string|int|array $tag = '', int|object $post = null )

so you could try e.g.

if( has_tag( 'test' ) ) { ... }

to check if the current post has the test tag.

1
  • ps: I should also mention that has_tag() is boolean, i.e. only returns true or false. – birgire Jan 22 '18 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.