Now Reading
How To Add Ads Inside Post Content In wordpress Without Plugins

How To Add Ads Inside Post Content In wordpress Without Plugins

by AdminAugust 25, 2016

Many of the WordPress blogs that have ads inside their post content. These ads are either after the first paragraph or the second paragraph in most cases. Most beginner bloggers wonder whether these sites insert ads manually when the write post content If there is a special code for this.wordpress Love

So let’s have a look easy and simple way to inserting you Adsense or any ads inside post content. In this article, we will show you to insert ads within your post content after specific paragraph.

Most of the beginner blogger think that add either manually this code which is extremely insufficient especially if you have to change advertisers. or they insert ads above or below their post content using one of the ad management plugins.

Simply install and activate the plugin insert post ads. If you don’t like using plugins, and want to do it the code way. then follow the step below;
Firstly you need to open your theme editor then go to function.php and open this file. After opening file function.php you need to copy the below code and paste in your function.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>Ads code goes here</div>’;
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
return $content;
// Parent Function that makes the magic happen
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 );

To adding your own ads or google Adsense code, simply edit $ad_code value where it says “Ads code goes here“. Once you do that, you are done. To change the paragraph number, simply you need to change the number 2 to another paragraph number whatever you want to choose the paragraph line.

we hope that this article helped you insert ads within your post content in WordPress blog. If you like this article please like and follow us on our social media community thanks in advance.

Please wait...
About The Author

Leave a Response