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

Davinder Singh Kainth

A digital creator with 15+ years of experience in Website Design, Development, SEO, and Content Creation to Podcasting at with the motto of "Be Smart, Keep Creating". A coach, consultant, and your dear geek friend ❖


  1. Friendship Bracelets on September 13, 2012 at 8:59 am

    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. AfroCoco on November 3, 2012 at 1:06 am

    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. Spooky on November 5, 2012 at 8:56 am

    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.

    • Editor on November 15, 2012 at 2:47 am

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

      • mastertwitter on September 8, 2013 at 5:56 am


        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.

        • Editor on September 9, 2013 at 1:33 pm

          Code has been updated, try again.

  4. Adewale Lagos on December 15, 2012 at 10:14 am

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

  5. ajit jain on December 25, 2012 at 6:11 am

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

  6. Bryan Eggers on May 25, 2013 at 4:08 am

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

  7. Damn on June 23, 2013 at 6:23 am

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

  8. telugunow on September 28, 2013 at 10:46 am

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

Leave a Comment