What is the correct way to write a conditional statement?

                    <?php if is_tag( 'Premium' ){
                     <a href="<?php the_permalink(); ?>" class="info"> Subscribe</a>

                    }else {

                    <a href="<?php the_permalink(); ?>" class="info">Read More</a>

Help Needed.

  • are you want help in php formatting of your code? Dec 2, 2013 at 17:26
  • yes, how can i add this in template. to show if the post has tag premium then show this or else.
    – luckyrajiv
    Dec 2, 2013 at 17:27
  • Personally, I would say the correct way to write any conditional is to add parenthesis around the statement: if(is_tag())
    – Howdy_McGee
    Dec 2, 2013 at 18:18

2 Answers 2


is_tag checks whether the page being displayed is the tag archive page for the named tag. It does not check whether the post in a Loop has that tag, which is what you ask: "...to show if the post has tag premium...". For that you need has_tag

if has_tag( 'premium' ){ ?>
    <a href="<?php the_permalink(); ?>" class="info"> Subscribe</a><?php
} else { ?>
    <a href="<?php the_permalink(); ?>" class="info">Read More</a><?php

Note that has_tag requires the tag slug and not the tag name, hence the lowercase.


try this

<?php if ( is_tag( 'Premium' ) ) : ?>
    <a href="<?php the_permalink(); ?>" class="info">Subscribe</a>
<?php else : ?>
    <a href="<?php the_permalink(); ?>" class="info">Read More</a>
<?php endif; ?>  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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