WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
are you want help in php formatting of your code? – Ravinder Kumar Dec 2 '13 at 17:26
yes, how can i add this in template. to show if the post has tag premium then show this or else. – jamesrotcher Dec 2 '13 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 '13 at 18:18
up vote 1 down vote accepted

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.

share|improve this answer

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; ?>  
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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