If you are a blogger who covers various topics under different categories and uses ad networks like Google Adsense, then you may sometimes want to remove ads from certain post categories.
So here is the code ( thanks to Keith and John ) which lets you remove ads from certain categories in Wordpress:-
<?php
if ( !in_category(5) && !in_category(10) ) {
?>
Your ad code here
<?php } ?>
In the above code, the number in brackets is the category id.
Finding Category ID in Wordpress 2.5
If you are using Wordpress 2.5 then to find the category id, just go to manage categories and then hover your mouse over a particular category and look at your browser status bar. You can find the category ID there.

And thats how you find the category id in WP 2.5 . We hope this technique helps you to manage ads on your blog in a better manner.
Enjoy this post? Subscribe to our RSS feed!




Great tip,
and I just subbed in RSS and love-love-love your blog so far — my reader gives me the last 10 posts and they’ve inspired my to start down your list of categories — very useful, clean, clear, simple; thanks.
(Your commas and their spacing is all messed up in Firefox, but I’m guessing you’re typing fast with all your good ideas flying out of your brain, so I mention it just FYI.)
great!
Thanks Girlpie and Buzzurls
Girlpie- Could you send me the screenshot of the page?..Even I am using Firefox and the commas and spaces appear fine to me.
Can’t send screen shots but I have a SnagIt jpg that I’ll email to you — just look at your ABOUT JEET BLOG info to the lower-right of these comments: the ellipses (the three dots, not really used correctly here — it’s NOT a “pause” — but it’s passable) needs a space after it;
the first period ending the first sentence needs a space after it and before the “This”;
the comma between “tips,online” and the next tree uses need to have a space after the comma (to look like “tips, online”);
and the last ellipses has an incorrect space before it, and is only two dots when it should be three. And you should have the two words “Read More” on the same line.
I wasn’t commenting on this particular post, (which also has some mistaken punctuation) but on the proofing job as a whole. Your content and overall look is so good, I just think you need a professional proofer so you can keep focused on the content! I’ll send the jpg in a sec… just gotta get your email –
Will email privately –
Doh! The long comment didn’t go through so I thought better of it and deleted it to send privately and now I see it did go through — again, with all due respect… it’s just about the proofing, not the swell content.
@GirlPie- Got your email and replied to it. Thanks for noticing.
jeet thanks for this tip.
is it work with wordpress 2.3?
@Ajay- it works with all versions of wordpress