3 Simple Ways to Insert Ads Inside Post in WordPress Site



Display ads within paragraphs in an article is one of effective ways to increase Ads Click-trough-rate.

Do you know why ?. It because content is the main things that your readers look for.

When people read your article, they will see the ads. And because the article in your blog is the most viewed part, so the ads inside it will be more visible than ads in other places.

Unfortunatelly, not all webmaster are able do this. So, through this post i will show you how to insert ads inside single post in wordpress with 3 ways.

Using Insert Post Ads Plugin

  1. Download and install Insert Ads Plugin here.
  2. Go to Post Adverts > Setting. Set it like the image below.
    Post Advert Setting
  3. After that, Go to Post Adverts > Add New.
    insert-post-ads
  4. Insert Ads Codes and set the position of ads
  5. Save. And Finish.

The other 2 ways are manually insert ads codes in theme files. If you don’t like to add more plugin to your blog, you can do these alternative ways.

The following steps are editing theme files through WordPress Theme Editor. But, it’s better if you already familiar to edit theme files through FTP or Cpanel.

Insert Codes in theme file : single.php

  1. Make sure the theme file permission is writabble.
  2. Go to Appearance > Editor.
  3. Choose and edit Single Post file (single.php).
  4. Search the code below :
    the_content();
  5. Then, replace it with the following codes.
    $where = 0;
    $content = apply_filters(‘the_content’, get_the_content());
    $content = explode(“</p>”, $content);
    for ($i = 0; $i <count($content); $i++) {
    if ($i == $where) { ?>
    <!- Your ads codes here ->
    <?php
    }
    echo $content[$i] . “</p>”;
    }
    – The red code is the number of paragraph where the ads will be placed under it.
  6. Save Changes and Finish.

Insert Codes in theme file : functions.php

  1. Make sure the theme file permission is writabble.
  2. Go to Appearance > Editor.
  3. Choose and edit Theme Functions file (functions.php).
  4. Insert the following code before ‘?>’ or in the bottom of other codes.
    //Insert ads.
    add_filter( ‘the_content’, ‘prefix_insert_post_ads’ );
    function prefix_insert_post_ads( $content ) {
    $ad_code = ‘Place your ads codes here‘;
    if ( is_single() && ! is_admin() ) {
    return prefix_insert_after_paragraph( $ad_code, 1, $content );
    }
    return $content;
    }// Parent Function
    function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
    $closing_p = ‘</p>’;
    $paragraphs = explode( $closing_p, $content );
    foreach ($paragraphs as $index => $paragraph) {
    if ( trim( $paragraph ) ) {
    $paragraphs[$index] .= $closing_p;
    }
    if ( $paragraph_id == $index + 1 ) {
    $paragraphs[$index] .= $insertion;
    }
    }
    return implode( ”, $paragraphs );
    }
    – The red code is the number of paragraph where the ads will be placed under it.
  5. Save Changes and Finish.

Defining Position of Ads

I realize that insert ads within the paragraphs is not enough. We have to define the ads position in order to tidy up the paragraph and ads layout.

You could positioning the ads to align-left, align-right or align-center by adding the wrapper div in your ads code. The each wrapper of position is shown below.

<div class=”float:left;margin-right:15px;margin-bottom:10px;position:relative;”>
<!– your ads code here –>
</div>
<div class=”float:none;display:block;margin:0 auto;position:relative;”>
<!– your ads code here –>
</div>

That’s all. Good luck!

If you have a question, you can ask it in the comment below.