How to Insert Ads within your Post Content in WordPress

I was wondering that how we can Insert Ads within your Post Content in WordPress. I was thinking that when we write the post at that time we can include the advertisement code.It becomes very much difficult to change advertisement after some time if we want to change it.

After searching for some time I found that we can have some code which will automatically include the advertisement code within the post.
Code will go in single.php file if we want to Insert Ads within your Post Content.

You will something like this

<?php the_content(); ?>

Replace this code with the following code.

<?php
$paragraphAfter= 5; //display after the third 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 can change number of paragraph after which you want to Insert Ads within your Post Content by changing $paragraphAfter value.

Referance Site See Here

admin