How to Insert Ads within your Post Content in WordPress

Interactive Online > Blog  > CMS  > WordPress  > How to Insert Ads within your Post Content in WordPress

How to Insert Ads within your Post Content in WordPress

Have you seen blogs that has ads inside their post content? Most beginners wonder whether these sites insert ads manually when they write the content, or if there is a special code for this. This article will show you a snippet that will let you enter ads within the post content after the first paragraph.

How to Insert Ads within your Post Content in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Add Content and Completely Manipulate Your WordPress RSS Feeds
  2. Display Feedburner Subscriber Count as Text in WordPress
  3. How to Add a New Post in WordPress and Utilize all the Features


Have you seen blogs that has ads inside their post content? These ads are either after the first paragraph or the second paragraph in most cases. Most beginners wonder whether these sites insert ads manually when they write the content, or if there is a special code for this. It would seem extremely inefficient if one enters the code manually specially if you had to switch advertisers after one year and you have over 200 articles. This article will show you a snippet that will let you enter ads within the post content after the first paragraph.

First open your single.php file and look for the content code that would look something like this:

<?php the content(); ?>

Replace that code with the codes below:

<?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>Your Text / Ads Go Here</div>

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

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

Source of this article is suspended by the host, we used Google Cache to get this tutorial and it works.

How to Insert Ads within your Post Content in WordPress is a post from: WPBeginner which is not allowed to be copied on other sites.

Related posts:

  1. How to Add Content and Completely Manipulate Your WordPress RSS Feeds
  2. Display Feedburner Subscriber Count as Text in WordPress
  3. How to Add a New Post in WordPress and Utilize all the Features

(read full article on source site)
Free Website for Your Dental Practice
See why our dental practice websites exceed the features & value of your typcial dentist website.
  • No cookie-cutter websites
  • No duplicate content
  • Custom built with a unique look and feel
  • Unique content written by professional writers
  • Set yourself apart from other dentists
  • The key to your online success!
* we never share your e-mail with third parties.