Have you ever wondered how exactly you could choose which categories do and which don’t display your advertisements?   Maybe you have a Sponsored Review category and want to make sure that all posts filed in that category don’t display any ads.

This is something that you as a user of WordPress have the ability to do without to much effort.  What you need to do is paste the following code into your blog around your advertisement code:

<?php if ( !in_category(10) && !in_category(11) ) { ?>

This is your existing advertising code.

<?php } ?>

Where it says 10 and 11 you will want to place the number assigned to your categories that you want to censor advertisements from. You can repeat where it says ‘&& !in_category(12)’ as needed until you’ve censored all categories.

Enjoy!

Kyle Eslick is WordPress enthusiast who took his passion for WordPress to the next level in 2007 by launching WPHacks.com as a place to share hacks, tutorials, etc. Follow Kyle on Twitter @KyleEslick!

  1. Todd Liebman says:

    Once I take an ad down from an individual category (which is being fed by AdSense) will I be able to place a new ad (not from AdSense) onto only that INDIVIDUAL category?

  2. Sandeep Khatri says:

    Hello,
    This code is not working. I have tried but didn’t worked. Can you please tell how to block ads from showing in posts of 1 or more specific categories?

Trackbacks/Pingbacks »

  1. Top 30 Most Wanted Wordpress Tricks and Hacks | Make Money Blogging Experiment says:
  2. 100+ Killer Wordpress Resources | Steffan Antonas' Blog says: