How do make your Adsense targeting for your post content in WordPress-Part 02?

  • Sharebar

In the first part, How do make your Adsense targeting for your post content in WordPress-Part 01?, I explained you how to wrap your post content with targeting tags automatically using wordpress filters. In the second part i will show you how to exclude certain parts of your posts from ad targeting.

We are going to use <!-- google_ad_section_start(weight=ignore) --> tag to disable ad targeting in certain parts of your posts. As i said before this is easy but not handy. Let’s add a shortcode for this to our functions.php:
1. Open functions.php file in your theme folder.
2. Insert the following code:

functions.php
1
2
3
function insert_ad_targeting_ignore_tag($atts, $content = null ){
    return '<!-- google_ad_section_start(weight=ignore) -->' . do_shortcode($content) . '<!-- google_ad_section_end -->';
}; add_shortcode('ignore', 'insert_ad_targeting_ignore_tag');

3. Save the file and upload it if needed.

Now you can wrap unimportant parts of your post using [[ignore]] & [[/ignore]] shortcode tags. This will be a lot easier 😉

Hope this helps you on your adsense optimization.

 

 

You can leave a response, or trackback from your own site.