Checking if a post belongs to a Wordpress category

If you need to check whether a post belongs to a certain category, you can use the following code in the single.php file

<?php if(in_category('cata-name')) { ?>
      post in category
<?php } else { ?>
      post not in category
<?php } ?>

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
The comment language code.