How to Insert Two Ads into Post Content (Without a Plugin)
-
I am trying to avoid using plugins that say they can do this.
I’m currently using the code below. It works great, and I’m able to set it to display a single ad unit, left aligned after the second paragraph.
Some posts on this site run as long as 4,000 words so I’d like to display a second DIFFERENT ad unit, right aligned at the 10th or 12th paragraph.
How do I modify this code to that?
<?php $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 class="alignleft">Ad Code Here</div> <?php } echo $content[$i] . “</p>”; } ?>
- The topic ‘How to Insert Two Ads into Post Content (Without a Plugin)’ is closed to new replies.