38 | Adsense Ad at the More Tag Position

g+

Surprise your readers with a google ad after clicking the ‘read more’ link – a strategic position to catch the attention of the viewer and increase your revenue.

Advertising does not get the same attention all over your page, as this report shows, some areas are ‘hotter’ than others, and the top of your content is one of the ‘hottest’.

Many of you insert the ‘more-tag’ after a short introductionary part of your content when writing your articles – usually to keep the design of the home page clean and easy to navigate.

When  the reader clicks on the ‘continue reading’ button, this already proves that the article has so far captured his attention – and the reader is more likely to follow any targeted advertising links, particular if these are seamlessly integrated into the main post content.

And the ‘more link’ will jump right into the position where the text on the home page ended.

It is your task to create the adsense so that the colors and design of the ads match the design of your post page.

The technical part: add this code into the template file functions.php of your wordpress theme; and replace the adsense code with your own:

add_filter('the_content', 'adsense_added_at_more_tag');
function adsense_added_at_more_tag($text) {
if( is_single() ) :
$ads_text = '<span>
<script type="text/javascript"><!--
google_ad_client = "pub-0123412341234123";
/* personal_development */
google_ad_slot = "1234512345";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</span>';
$pos1 = strpos($text, '<span id="more-');
$pos2 = strpos($text, '</span>', $pos1);
$text1 = substr($text, 0, $pos2);
$text2 = substr($text, $pos2);
$text = $text1 . $ads_text . $text2;
endif;
return $text;
}

You can then add some styling such as alignment by using the css class .adsense in style.css of your theme:

.adsense {
display:block;
width:100%;
text-align: center;
background: #f8f8f8;
}
This entry was posted in Tips & Tricks, WordPress and tagged , , , , , . Bookmark the permalink.

2 Responses to Adsense Ad at the More Tag Position

  1. Stefan comments:

    Hello,

    thank you for the nice code, it’s very usefull.

    I changed two parts:
    03: if( is_single() ) : -> if( is_single() && in_category(‘news’)) : // I want adsense only in articles in the news category, not in other categories
    19: $text1 = substr($text, 0, $pos2); -> $text1 = substr($text, 0, ($pos2+7)); // the whole more-tag, including
    20: $text2 = substr($text, $pos2); -> $text2 = substr($text, ($pos2+7)); // continue after the closing-more-tag
    If I don’t change line 19 and 20, the scripts puts the adsense code in the middle of the more tag, that’s not nice.

    Hope I could help other people.

    Greetings Stefan

  2. Pingback: How to adsense ad replace with more tag | wpBite.com

    g+

    06/08/2011 | […] Source : http://www.transformationpowertools.com/wordpress/adsense-ad-at-more-tag-fold […]

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*