How to Disable Ads on the Specific Posts?


One of my site has recently received a warning of violation of policy due to placing adsense ads on a post that has a content subject not allowed. Actually, that post has been ranked in the first page of google and I certainly don’t want to remove that post just because I can’t write specific topics on the pages that have adsense. So my solution is to disable ads on that particular page without re-wording/modification of that post.

Gogle-Adsense How to Disable Ads on the Specific Posts? adsense php programming languages wordpress

Google Adsense Improvement Tips

Disable Ads Before, In, or After Posts

If you put ads using the the_content filter, you can usually put ads before, after on in the middle of a post. In this case, you could edit the wordpress child theme functions.php template:

1
2
3
4
5
6
7
8
9
10
11
add_filter('the_content', 'show_ads');
function shot_ads($content) {
  global $post;
  // 729 is the ID of the specific post, change accordingly.
  $noads = in_array($post->ID, array(729)); 
  if (!$noads) {
     // assume ads is shown before the content of a post
     return "<ads code here >" . $content;
  }
  return $content;
}
add_filter('the_content', 'show_ads');
function shot_ads($content) {
  global $post;
  // 729 is the ID of the specific post, change accordingly.
  $noads = in_array($post->ID, array(729)); 
  if (!$noads) {
     // assume ads is shown before the content of a post
     return "<ads code here >" . $content;
  }
  return $content;
}

Disable Ads on the SideBar

If you have long e.g. 350×600 or responsive ads showing on the sidebar, you would need to install PHP Code Widget first to enable PHP code on the widget. After, you will need to wrap your ads code similarly. e.g.

1
2
3
4
5
6
7
<?php
// 129 is the ID of the specific post, change accordingly.
$noads = in_array($post->ID, array(129)); 
if (!$noads) {
  echo "Your Ads here";
}
?>
<?php
// 129 is the ID of the specific post, change accordingly.
$noads = in_array($post->ID, array(129)); 
if (!$noads) {
  echo "Your Ads here";
}
?>

This is a quick fix to the adsense policy violation if you don’t know how to modify the content and you don’t want to simply delete the violation post.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
397 words
Last Post: How to Implement The Sgn Function in C++?
Next Post: SEO Tip - How to Remove Broken Links?

The Permanent URL is: How to Disable Ads on the Specific Posts?

Leave a Reply