How to Automatically Inset Ads in all WordPress Post Content

How to Insert Advertisements in WordPress Post Content

Inserting Ads in post content can lead to explosive CTR (Click Through Rate). It’s a good practice to insert advertisements in WordPress post content especially if your CTR has been low. In this article, i do not only show you how to create Ads in WordPress post content, but also how to change Ads with and without Ad Management Plugins.

Many claim this annoys readers but somehow i do not agree with this. If your readers are used to seeing Ads at a particular section of your post content, they should not complain.

Posting advertisements in WordPress content can be a great way of generating more revenue for your website. A high CTR means more revenue and such Ads usually receive high-click through rates.

For Google Adsense publishers, i highly recommend placing Ads in post content. Adsense shows relevant Ads and nothing spammy. Mind the Ad network you use because you need to stay away from having low quality Ads displayed on your website, especially in the content. This is what annoys most readers.

If the displayed Ads are of good quality, its unlikely that your readers will complain.

So how do we Automatically Insert Ads in all WordPress Post Content?

To get started, we shall need to add some CSS code on our style.css file for the <div> container that is going to hold the advertisement.

This container has to be floated either left or right depending on where you want the Ad to appear. Also, It’s display has to be changed to inline so that it doesn’t cover the whole line. The height and width may vary depending on your Ad preference. Copy the code below and add it in your style.css file.

.adcontainer {
    float: left;
    width: 300px;
    padding: 5px 15px 5px 0px;
    background: none;

For this example, our Ad will appear on the left, displayed in an inline manner. This implicated the Ad will be on the left and right to it is out content.

Want to know why i find this awesome? The reader has to see the Ad by all means. They can only choose to ignore it BUT still if you are using CPM networks, you should add something.

Next, we shall trim paragraphs on the content using the Trim() PHP function. We shall also add where the advert will appear. It could be after the first paragraph, second and so on. You can apply all these tweaks to this code.

So lets create a function that holds the advertisement code. Paste the code below in your theme’s functions.php file.

add_filter( 'the_content', 'insert_ads' );

function insert_ads( $postcontent ) {
  $my_code = '<div class="adcontainer">
          // Paste your Ad code here.....

  if ( ! is_admin() && is_single() ) {
    return insert_code_after_p( $my_code, 1, $postcontent );
  return $postcontent;

In the code above, we ensure the Ad appears only in the single view. The function: insert_code_after_p( arg1, arg2, arg3 ) holds the Ad code, which could be a banner or script depending on what network you are using.

The function takes in 3 arguments with paragraphs being the second. So if you would like to add an Advert after the second paragraph, change 1 to 2. In the code above, the Ad code will appear after the first paragraph.

This brings us to the third and last bit. The code above cannot work without the code below. Copy and paste this code in your theme’s functions.php file. You could paste it right after the first code for uniformity.

function insert_code_after_p( $code_insert, $p_id, $postcontent ) {
  $end_p = '</p>';
  $paragraphs = explode( $end_p, $postcontent );
  foreach ($paragraphs as $index => $paragraph) {

    if ( trim( $paragraph ) ) {
      $paragraphs[$index] .= $end_p;

    if ( $p_id == $index + 1 ) {
      $paragraphs[$index] .= $code_insert;
  return implode( '', $paragraphs );

If you look at the code above you realize this function is part of the function that builds up the first function. Without it, the first function would be irrelevant. It’s the function that trims down the paragraphs and inserts our ad code in them.

The code is tested and should work for you. Just add it and see your revenue increase.

Using Ad Management Plugins

There are lots of Ad management plugins that can automate this for you BUT just like i’ve always emphasized, only use plugins when you have no option. You are not going to keep relying on plugin authors for certain functionalities of your website.

This is why i always advise bloggers to take short courses on WordPress and PHP before they kick-start their blogging journey. This will help them change a lot without relying on anyone in the times to come.

You do not necessarily have to take advanced courses. Novice courses and completely understanding how both systems work can do. You can always google the rest later.

The simple line of code above will save you from using plugins. Some plugins are heavy and consume lots of resources. In some scenarios, their authors fetch analytics data from your website to perfect their plugin. I am against this and do not support it.

However, just in case you intend to use plugins for this, you could choose from the 5 Ad management plugins below.

  1. Adning Advertising By Tunafish (Premium)
  2. AdSense Plugin by WP QUADS (Freemium)
  3. WordPress Ad Widget (Free)
  4. AdPlugg WordPress Ad Plugin
  5. AdRotate Free WordPress Plugin

Recommended Number of Ads

Its always not good to have so many Ads in your post content and website in general. Depending on your article length, a maximum of 3 Ads per page, with just 1 in the post content should perform well.

Many publishers add up to seven Ads on a single page in a big to raise their CTR and revenue. Do not fall in this trap! When a web page has too many Advertisements, most users are likely to bounce back from your website and this often affects your SEO. When your bounce rate increases, you’ll lose majority of your rankings and traffic.

So much as you want to make money on your website, you should always endeavor to put your readers first after creating valuable content. This will definitely help you increase your monthly revenue.

Have you been using Ad management plugins or you code your Ads the hard way like i do? Or is there any Bad-ass plugin better than the ones above? How is your Ads experience? You can share it with us in the comment section below because we’d love to hear from you.

Authored By Kolo Pius

Kolo Pius is the founder of TutorialFAQ. He writes Badass articles for it and is an avid traveler too. Most of the time he travels while blogging and coding. You can hire me for your next Web Project, Mobile Project or SEO Services. About Me | Facebook | Twitter


Leave a Comment

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

More FAQs

Share via
Copy link