Share:
Notifications
Clear all

NOTICE BOARD: 

99.9% QUESTIONS ALREADY HAVE WELL RESEARCHED ANSWERS

We do not allow copy and paste-like most forums are known for. Our posts are unique and all member must abide with this rule or get kicked out!!!

How To Add Adsense Ads Within Post  

   RSS

0
Topic starter

This guide shows you how I add Adsense ads after the first paragraph of a blog post to convert better and you can decide by changing just a line which paragraph you want it to display.

Am A Crypto/Blockchain Enthusiast, SEO Expert and Web/Digital Marketing Consultant At Foskaay. Available to work remotely as a decade+ Experienced FREELANCER - Skilled in SEO (Search Engine Optimization Consultant), Copywriting, WordPress, Social Media, Marketing Strategy, Public Speaking, Team Building, Cryptocurrency/Blockchain and Online Marketing. Strong business development professional and founder of many digital-based projects including world no1 crypto dictionary app and best questions and answers platform in the world!

1 Answer
0
Topic starter

One of the best converting place for AdSense ads in when placed in your content and one of such place is the first paragraph according to Rankxl.

So, follow these steps to implement the ads code automatically across all your blog posts.

1) Put the following in your function.php file:

 

function insert_ad_block( $text ) {

if ( is_single() ) :

$ads_text = 'PUT YOUR ADSENSE ADS CODE HERE';
$split_by = "\n";
$insert_after = 1; //number of paragraphs

// make array of paragraphs
$paragraphs = explode( $split_by, $text);

// if array elements are less than $insert_after set the insert point at the end
$len = count( $paragraphs );
if ( $len < $insert_after ) $insert_after = $len; // insert $ads_text into the array at the specified point
array_splice( $paragraphs, $insert_after, 0, $ads_text ); // loop through array and build string for output
foreach( $paragraphs as $paragraph ) { $new_text .= $paragraph; } return $new_text; endif; return $text; }

add_filter('the_content', 'insert_ad_block');

 

 

2) Save the function.php file

3) Visit any of your posts and refresh it. It should display now if done correctly

NOTE: You can edit the "1" and change to 2 or 3 or whatever paragraph number you want.

It works fine for me if you click on this page About Foskaay Forum but not working on the forum because it does not use default wp posting so the function.php file does not impact it.

This post was modified 1 year ago by oskaaay

Am A Crypto/Blockchain Enthusiast, SEO Expert and Web/Digital Marketing Consultant At Foskaay. Available to work remotely as a decade+ Experienced FREELANCER - Skilled in SEO (Search Engine Optimization Consultant), Copywriting, WordPress, Social Media, Marketing Strategy, Public Speaking, Team Building, Cryptocurrency/Blockchain and Online Marketing. Strong business development professional and founder of many digital-based projects including world no1 crypto dictionary app and best questions and answers platform in the world!

Share: