How To Remove Ads On Posts In Certain Categories

ADVERTISEMENTS

Have you ever wanted to remove ads on posts belonging to certain categories only? Or wanted to remove ads on all your sponsored review posts?

Here’s the code to do it in WordPress:

if ( !in_category(15) && !in_category(23) && !in_category(14) && !in_category(20)) {
?>
Your ad code here

In the above code 15, 23, 14 and 20 are category IDs, replace them with the IDs of the categories you don’t want ads in.

I am currently using this code to remove AdSense and Kontera ads from my Blogging, Make Money Online, WordPress and WordPress Plugin categories. Thanks to Keith for the code.

banner

Search JohnTP.com or view a random post

To receive this blogs articles for FREE on your email inbox, just enter your email address below and click 'Go':

Enter your email address: or .

Find out what I am doing currently by .

20 responses so far, Leave a comment

  1. 1

    sofish

    October 19, 2007 at 3:11 pm

    Is the code can also remove Images in the post in some category?

  2. 2

    indyank

    October 19, 2007 at 3:22 pm

    cool keith and John..

    I am not sure that I understood sofish’s question…We post different images for different posts and it is not a script like we use for adsense or kontera…so if you don’t want have images for posts in certain categories,just don’t post or embed them.
    if u r referring to image ads, then yes the above script will work for sure…

  3. 3

    pchere

    October 19, 2007 at 7:09 pm

    Thanks for posting this great tip. I was looking around on how to do this. This also gives lots of ideas for more modifications. :-)

  4. 4

    Keith Dsouza

    October 19, 2007 at 9:40 pm

    Thanks for the mention :-)

  5. 5

    Bloddard

    October 20, 2007 at 4:02 am

    Thanks….

  6. 6

    indyank

    October 20, 2007 at 12:51 pm

    Hmm…think i should be doing what keith is doing…Definitely this is the easiest tip for anyone who even knows a bit of software…but I realize that the fact is several people(who are not into IT) may not be aware of even this, though they may have popular tech blogs…guess even I should be posting more stuff like this, keeping this fact in mind…

  7. 7

    Rossa

    October 21, 2007 at 10:27 pm

    Thank’s John - I will try it on my blog

  8. 8

    Vijay

    October 22, 2007 at 2:01 pm

    Thanks John, I needed something like this for the sponsored reviews category.. Also, do you have any code to not display all the pages created on the top. Meaning, to exclude some pages from being displayed in the nav bar on top.

    Thanks!

  9. 9

    JohnTP

    October 22, 2007 at 11:46 pm

    pchere- I am glad I could help :)

    Vijay- This should help: How To Hide Pages from Showing Up In Your Main Menu

  10. 10

    Nirmal

    October 24, 2007 at 3:29 pm

    John,
    Simple and easy tip, I was also looking for something like this.

  11. 11

    Deep

    October 24, 2007 at 6:22 pm

    one more tip.. if you wish to remove ads for any particular post then
    you can do something like this too:


    if ($show_ad == "N")
    {
    $adcode = ""
    }
    else
    {
    $adcode = "xxx"
    }

    repplace xxx with your ad code.

    Now it wont show the ads in posts where you have mentioned following
    code < ? p h p $show_ad == "N"; ? >

    Make sure you have runphp plugin installed and you have allowed to run
    PHP code for that post and also take of spaces between < ? and php

  12. 12

    Garchoune

    October 26, 2007 at 2:32 am

    thanks man i will it on my blog
    well done

  13. 13

    Vijay

    October 27, 2007 at 1:47 pm

    Thanks for the help, John

  14. 14

    Jamdo

    November 24, 2007 at 11:04 am

    Oh cool - that is going to save me so much messing around with templates.

  15. 15

    Graphic Boards

    November 29, 2007 at 12:31 am

    Well done my friend i will test it on my blog

Have something to say?




Copyright ©2005-2008 JohnTP, All rights reserved.