How to Insert Ads within your Post Content in WordPress

By on Dec 14, 2010 in Wordpress Tutorials |

Share On GoogleShare On FacebookShare On Twitter

wpadsIf you have written huge number of posts and want to insert and ad within the post content then its not possible to edit all the posts and put the ad code individually in each post.

If you wan to insert ads within your post content in wordpress then follow the steps below.

Open single.php file located in your theme folder and look for the code that would look something like shown below:

<?php the_content(); ?>

Replace that code with the codes below:

$paragraphAfter= 1; //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>Your Text / Ads Go Here</div>

<?php }
echo $content[$i] . "</p>";
} ?>

You may change the number of paragraphs by changing $paragraph After line.