WordPress if has tag or in category

<?php if (has_tag('abc') && (in_category('d')) { echo '<div class="xxx">' ; } else { echo '<div class="yyy">' ; } ; ?>

Im using the above but it returns an error, am i doing anything wrong? Thanks for looking

Related posts

Leave a Reply

2 comments

  1. You are missing a closing parentheses ) in your if statement.

    Fix it to this:

    <?php if ( has_tag('abc') && (in_category('d')) ) { echo '<div class="xxx">' ; } else { echo '<div class="yyy">' ; } ; ?>
    
  2. There are syntax errors in your code try this

    <?php if ( has_tag('abc') && in_category('d') ) { echo '<div class="xxx">'; } else { echo '<div class="yyy">'; } ?>
    

    has_tag and in_category only works in WordPress loop if you do not pass post id as second parameter.