Add Advertisements to WordPress Post after Paragraph

By | February 12, 2012

In Many website you might see ads in the middle of the post or after a particular word counts. This is done by changing the content loop in the single.php file. In this demo you can post ads after a particular paragraph. Such as 1 passage, 2 passage …etc.

Advertisements Networks

Advertisements Networks

Steps To be Followed [To show ADS after Paragraph]

Step1: Open your WordPress theme editor. Appearance –>Editor

Step2: Look for the single.php file & Open it. –>single.php

Step3: Surf down to find < ?php the_content; ?> (or) < ?php the_content(‘Read more…’); ?> (or) < ?php the_content(“Continue reading ” . the_title(”, ”, false)); ?>

Step4: Exchange the line with the below code.

[code]
<?php
$paragraphAfter= 2; //display after the second paragraph
$content = apply_filters(‘the_content’, get_the_content());
$content = explode("</p>", $content);
for ($i = 0; $i <count($content); $i++ ) {
if ($i == $paragraphAfter) { ?>
<div id="adspost">
Advertisements code here:
</div>
<?php }
echo $content[$i] . "</p>";
} ?>
[/code]
Code Download Here

One thought on “Add Advertisements to WordPress Post after Paragraph

Leave a Reply

Your email address will not be published. Required fields are marked *