Wordpress PHP Detect category a post is in


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $post = $wp_query->post;
  3.  
  4. if ( in_category('press-releases')) {
  5. echo '<div class="backToMain"><a href="/buyers-news/category/press-releases/">&lt; Back to Press Releases</a></div>';
  6. } else if ( in_category('media-coverage')) {
  7. echo '<div class="backToMain"><a href="/buyers-news/category/media-coverage/">&lt; Back to Media Coverage</a></div>';
  8. } else {
  9. echo '<div class="backToMain"><a href="/buyers-news/category/media-coverage/">&lt; Back</a></div>';
  10. }
  11.  
  12. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.