Last updated on November 28, 2011. Tags: ads placement, WordPress post
You might have noticed a small change in my layout these past few days. The "summary" part on top is gone, and the Adsense ads below it is moved under the first paragraph.
Placing ads between paragraphs of the main content is one of the most effective strategy in monetizing your website. It's a similar concept as putting the ads between parts of a television show. It's certain that visitors will notice them as they scroll down reading your content .
One way of doing this is to manually insert the ad code between post paragraphs. This method is inconvenient because you need to insert the ad code every time you write a new post.
The other way is what we will discuss in this article. To insert an ad unit between the first and the second paragraph of a post, open the single.php file and look for the following line of code:
<?php the_content(); ?>
This code may not appear exactly as shown above. Sometimes there are stuff between the parentheses like for example <?php the_content('Read more...'); ?>. Replace this code with the one shown below:
<?php
$paragraphAfter= 1; //shows the ad after paragraph 1
$content = apply_filters('the_content', get_the_content());
$content = explode("</p>", $content);
for ($i = 0; $i <count($content); $i++) {
if ($i == $paragraphAfter) { ?>
<!-- START OF AD CODE -->
PASTE AD CODE HERE
<!-- END OF AD CODE -->
<?php
}
echo $content[$i] . "</p>";
} ?>
In the above code, you can insert the ad code provided by Adsense (also works in Chitika, Bidvertiser, etc) in the line labeled as PASTE AD CODE HERE. The number 1 in the second line indicates that the ad will appear after the first paragraph. In case you want the ad to appear after the second or third paragraph, just replace 1 with 2 or 3 respectively.
This tweak also works with WordPress static page, just look for the <?php the_content(); ?> code in the page.php instead of single.php.
This was last tested in WordPress 3.1.2 (confirmed June 30, 2011) and would likely work to all versions close to it. If you have a later version of WordPress and this tweak does not seem to work, please let me know so I can study it and make the necessary adjustments.
Posted by Greten on October 7, 2009 under Adsense / Ads Embedding Tips, WordPress
Comment Rules and Reminders
Posted by Piseth on 05.19.10 2:57 am
This is amazing, it works very well on my blog. You can check it out. thanks
Posted by Tony Tran – Android How to on 08.10.10 9:04 am
I just searching it for my wordpress blog and get success. Thank you for your great tips.
Edit by Greten: Please include your actual name in the name field whenever you comment. Found your name in the about section of your website. Thanks!