Google Adsense is one of the Best Ways to earn by showing ads in any standard website. If you have a lot of traffic in your site then your earn will touch the sky. Actually there is no limit to earn a lot by showing Adsense Ads in any site. So any one can earn unlimited dollar by using Adsense ads in a Google approved site. The best advantage of Adsense is if Google approve your site once then you can use your Adsense codes in 500 websites. This is really a great opportunity given by the Google authority. Where as if you want to use Bing or yahoo ads in your site then you have to approve every site manually by the Bing or yahoo authority. But in the case of Google you have to keep in mind that you can’t violate their terms and conditions.
Adsense Ads Right Before The Last Paragraph
Now let’s come to the point. As I am blogging since 2010 from that year I have tried to learn new tips and tricks. Many new bloggers tried to the best to approve their sites for Adsense. But after approving Adsense account by the google authority they want to set their Adsense ads in different places in a post. But for the want of coding knowledge they search a lot in google to get their right answers. Sometimes they get the answers but don’t understand the code. From that perspective I have written this post today.
Somebody asked me that How to Set Adsense Ads Right Before The Last Paragraph ? So let’s get the code. Copy the code and put this at the end of your functions.php file. N.B. Don’t forget to keep the back up of original functions.php file before adding the given code. You have to add Your Chosen Adsense Code by replacing Your Adsense Code text. It’s really very easy.
function ads_added_above_last_p($text) { if( is_single() ) : $ads_text = '<div class="a" style="text-align: center;">Your Adsense Code</div>'; if($pos1 =strrpos($text, ' ')){ $text1 = substr($text, 0, $pos1); $text2 = substr($text, $pos1); $text = $text1 . $ads_text . $text2; } endif; return $text; } add_filter('the_content', 'ads_added_above_last_p');
Necessity of this type of code:
Now you can ask me that you can also do it by using some famous plugins like easy Adsense or quick Adsense. The answer is there are a lot of bloggers or website owners who don’t want to use plugin to show Adsense ads. They always prefer simple code which I have given above. On the other hand all plugins are not coded perfectly . Only very few plugins can decrease your sites speed. But most of those increase your site’s loading speed. But the above given code will increase your site’s speed. So we should show Adsense ads by using standard above mentioned code. N.B. Don’t use the justify option for the last para of a post. Otherwise you will not see any Adsense ads right before the last paragraph of your post.
Check a Site’s Loading Time, HTML Errors and SEO
How to Load Your Site Fastly-(100% working)
It will always be better to use only compulsory plugins as they increase sites’ loading speed. Somebody says that you can use a lot of plugins. My question is to them that if this statement is true then why godaddy.com has created P3 Profiler Plugin to find out that which plugin is decreasing a sites speed. Perhaps you have got my answer. If you have any question or feedback then please leave you comment in the comment section. It will help this sites to take the right decision on How to Set Adsense Ads Right Before The Last Paragraph. Stay connected with eTunesCafe to get new IT Tips and Tricks by liking our Facebook Fan Page facebook.com/etunescafe and also follow in Twitter.
U can simply use AD Injection plugin to set that and even character no paragraph, using WordPress worth trying Ad injection plugin.
Shawon vai! Thanks for your comment
Very helpful tips, thank you………
nice website. this site is helpful to all of us.
Your code is not working in my case. I guess there is some problem in this line:
if($pos1 =strrpos($text, ‘ ‘))
There is no final string position defined. I guess using could work which would search for the last tag i.e. last paragraph but somehow it was still not working in my case. So, I made use of parameterized explode() function which finally worked for me. You can see the code below:
function insert_ad_block( $text ) {
if ( is_single() ) :
$ads_text = ‘My Ad Code Here’;
$split_by = “\n”;
$insert_after = 2; //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');
Very helpful tips, thank you so much………
great info. never been on this site before. what’s it all about?