October 5, 2012

Textual description of firstImageUrl

How To Hide Adsense Ad On Certain WordPress Posts

|
 Probably you have certain blog posts which are not suitable for Adsense ads.

So, you wanted to exclude or hide them away from that page.

For instance the blog post with adult content or even your About page, Disclaimer or Private Policy page.

How To Hide Adsense Ads On Certain WordPress Posts

Here is how to do it:

1.Hide Adsense Code Which Is In A widget

You can use Widget Logic plugin.

or Conditional Widgets plugin.


2. Hide One Adsense Code In Single Post (single.php) Template.

Go to Appearance >>Editor >> Single Post (single.php).

Look for your Adsense code.

Now do this:

<?php if($post->ID != xxx): ?>
(Adsense code here)<?php endif; ?>
xxx is the ID number of the blog post.

How To Find Post ID Number

You can find it by going to "All Posts" under "Posts".

Put your cursor over that particular post title.

You should see something like this: your blog domain/wp-admin/post.php?post=357&action=edit.

For this example, the XXX is 357.

So now, the code should like this:

<?php if($post->ID != 357): ?>
<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxxx";
/* 336x280, created 02/06/11 */
google_ad_slot = "6379290360";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/s
how_ads.js"></script>)
<?php endif; ?>
in your single post template.

Then click "Update File" button.