Insert Ads In The Post Content After 1st Paragraph in WordPress
August 24, 2012 by | No Comments
How to Insert Ads In your Post Content After 1st Paragraph in WordPress
There are many ways to insert adsense or other advertisement in your WordPress post/page content, you can insert it before the content or after the content, but how to insert your ad in the post? I mean after the first paragraph, or after the second paragraph.
First open your single.php file and look for the content code that would look something like this:
<?php the_content(); ?>
Then you can replace that code with the codes below:
<?php
$paragraphAfter= 2; //display after the first paragraph
$content = apply_filters('the_content', get_the_content());
$content = explode("</p>", $content);
for ($i = 0; $i <count($content); $i++ ) {
if ($i == $paragraphAfter) { ?>
<div>Insert Ads Here</div>
<?php }
echo $content[$i] . "</p>";
} ?>
You may change the number of paragraphs by changing $paragraphAfter line.
$paragraphafter= 2; //display after the first paragraph,adsense under paragraph,php studiopress first paragraph,studiopress google adsense paragraph,woothemes tumbnail after 2nd paragraph,wordpress insert content after first paragraph












