How to block, disable Adsense ads on specific posts in WordPress

Google Adsense is considered best medium to monetize online content. Lot of webmasters use Google Adsense advertisements on their websites, blogs to earn and make living. Due to strict Adsense requirements, you may want to disable display of ads on specific posts containing sensitive content. You can easily implement this by following method and prevent Google Adsense ads from showing on specific posts.

Code to block Adsense ads on specific WordPress posts

1. Add the first part of the code to header.php file of your WordPress blog. For Genesis users, you can goto Genesis > Theme Settings and paste this in header script area. After you paste the code, make sure you change post IDs in the code or add more post IDs (like 82959, 82960 in the code).

2. Then paste the second part of the code to place where you want to display adsense ads. If you want to display on the sidebar, then drag text widget to specific sidebar and paste the code. For manually displaying on each post content area, paste it in single.php file at appropriate area.

Genesis users can paste in sidebar widget area. To display this in content area, use Simple Hooks plugin and paste in the hook area where you want to display ads.

You can disable Google Adsense ads on specific posts, by adding post IDs in code as shown in step 1 above. Quick and easy way to prevent Adsense ads from showing up on specific posts on WordPress blog. Credit Sandip Dedhia

SHARE

Comments

  1. Friendship Bracelets says:

    This is cool! i have wristbands site, and a blog. so i just wanted to remove ads on some specific post. n this way it will be very useful. i got here what i wanted to.

  2. Thanks for this great tip. Sometimes, it is very important to disable adsense serving to some posts otherwise Google can block ads to your site.

  3. Hello, I’m interested to know if this can be made to work with other ad networks, or just Adsense? I’m currently working with a CPM network and they requested their ads only appear on family-friendly pages.

    • You can use this code for any type of ads. Just paste your cpm ad code in-place of Adsense code.

      • mastertwitter says:

        Hi!

        I placed your code:

        // Add post IDs separated by coma e.g 1792 and 300 are post IDs of the post on which you want to block the ads
        ID,$adsense_blck_post,true)) $ad_flg=0; ?>

        At the top of header.php … but when I load a post from my page, I get an error to line 1.

        Do you know how to fix this? Thanks.

  4. Adewale Lagos says:

    thanks for this article, pls can this be used to block add on a page too. Thanks

  5. not working please help getting error on Parse error: syntax error, unexpected ‘?’ in header.php on line 54

  6. Bryan Eggers says:

    Doesn’t work for me, either. Anyone know what’s wrong?

  7. your code a bit messy but It really works, thanks!

  8. Hi it is not working for internet explorer..working for firefox. also add an else statement to display other ad if criteria not met.

Speak Your Mind

*

Subscribe to our mailing list

* indicates required
Close