How To Remove Ads On Posts In Certain Categories
ADVERTISEMENTSHave 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.
Search JohnTP.com or view a random post
Related Articles
Find out what I am doing currently by .
Posted on October 19th, 2007 | Category: WordPress |
sofish
October 19, 2007 at 3:11 pm
Is the code can also remove Images in the post in some category?
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…
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.
Keith Dsouza
October 19, 2007 at 9:40 pm
Thanks for the mention
Bloddard
October 20, 2007 at 4:02 am
Thanks….
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…
Rossa
October 21, 2007 at 10:27 pm
Thank’s John - I will try it on my blog
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!
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
Nirmal
October 24, 2007 at 3:29 pm
John,
Simple and easy tip, I was also looking for something like this.
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
Garchoune
October 26, 2007 at 2:32 am
thanks man i will it on my blog
well done
Vijay
October 27, 2007 at 1:47 pm
Thanks for the help, John
Jamdo
November 24, 2007 at 11:04 am
Oh cool - that is going to save me so much messing around with templates.
Graphic Boards
November 29, 2007 at 12:31 am
Well done my friend i will test it on my blog