Exclude Adsense From Specific WordPress Posts

For one reason or another, you may decided that you don’t want Google Adsense ads appearing within certain posts on your WordPress blog. It’s a difficult task since you most likely added the Adsense ad code within the template file.

Using PHP and with just a slight change to your code, you can exclude Adsense ads from specific posts.

Let’s say that I want to exclude Adsense ads from 3 posts:

  • How to Enjoy Your Vacation
  • The Best Android Apps
  • WordPress For Dummies

I would exclude each one by using the slug for each post with this code
<?php
if (!is_single(array('how-to-enjoy-your-vacation','the-best-android-apps','wordpress-for-dummies')))
{
?>
Your Adsense code
<?php
}
?>

You can also exclude posts via the post ID.
 if (!is_single(array('133','145','200')))  
{
?>
Your Adsense code
<?php
}
?>

2 thoughts on “Exclude Adsense From Specific WordPress Posts”

Leave a Comment