Insert Ads inside the WordPress Blog Post Content

How to Insert Ads within your Post Content in WordPress
ads after 2 column

WordPress user often wants to insert ads inside the posts or between 2 paragraph of the post body. Which can easily do in Google Blogger. Most of the Beginner insert ad code manually in each post. But this is very hard to edit each post and add ads code. If you have published good number of post then this may impossible.

Sometime WordPress user may change their Advertiser and due to this their old code won't work and this is extremely hard to remove old advertiser code by editing each and every posts. So I will show you how to insert ads inside WordPress Blog Posts in between 2 paragraph.

First of all I will use a simple plugin and then I will show you by adding a code block you would able to display ads in WordPress Blog  post content.

Step 1 Sign in to your WordPress account and from Dashboard Click on Plugins-> Add New

Step 2 Now type Insert Post Ads on Plugin search box and click on Search link.

install now

Step 3 Finally Install the Plugin and Activate it. A new Post Advert Menu will appear on existing Menu.

post advert

To get the code directly and for manual installation please visit the below link
  • http://wordpress.org/plugins/insert-post-ads/


Step 4 Now click on Post Advert ->Add New and Write Advert Title, Paste your ad code there and finally select the number of Paragraph where you want to display ads. And simply hit the Publish button from top right corner of the screen.

advert title

Step 5 Next go to Post Adverts -> Settings and select which post types you want to show your ads on. There are different post type such as posts, pages, and custom post types.

settings

How to Insert Ads inside post body without using Plugins

Many Blogger don't want to use any plugins because it increase loading time. So we can also insert ad by without using any plugins. To do this just follow the below steps-

Step 1 Sign in to your WordPress account and from Dashboard Click on

Step 2 From Dashboard Click on Appearance -> Editor and click to open Theme’s functions.php
from right sidebar.

theme function

Step 3 Now copy the below code and Paste it on Editor Panel.

<?php
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div>Paste your Ads code here</div>';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
}
return $content;
}
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 );
}

Step 4 Finally Click on Update File Button from bottom of the screen.

Customization

  • Replace Paste your Ads code here with your ad code.
  • Change 2 for indicating the number of paragraph where ad will appear.

Hope with the help of this tutorial you would able to display Ads inside WordPress Blog post body. And if you think this tutorial help you then kindly consider to like our Facebook Fan page. 
Go Up