How to Insert Adsense Ads Inside Blog Posts

Can you display Adsense ads inside blog posts? In-text ads are popular nowadays. There is no doubt that in-content ads encourage readers to click more, and the higher CTR can earn you more money. While it is easy to add Adsense ads below post titles or after post content, how can you add it inside articles?

Why not use WordPress Ad Plugins?

Of course, there are very powerful Adsense plugins that can let you perform custom ad placements almost anywhere you want. But I prefer to add code to functions.php and keep it simple, as much of the features provided by plugins might not be needed.

So how can you add your adsense like this?

adsense middle

Add Adsense Inside Post Content

Here is the code you need to add to the functions.php file of your WordPress theme. [Note it is a good idea to keep backup of functions.php file and any error can make your site unusable and you need to restore the file via FTP]

add_filter( 'the_content', 'qot' );
function qot( $content ) {
if( !is_singular() )
return $content;

$paragraphAfter = 5;
$content = explode ( "</p>", $content );
$new_content = '';
for ( $i = 0; $i < count ( $content ); $i ++ ) {
if ( $i == $paragraphAfter ) {
$new_content .= '<div class="middle-ads">';
$new_content .= 'ADSENSE CODE';
$new_content .= '</div>';
$new_content .= $content[$i] . "</p>";
return $new_content;

Insert Ad Code explained

1. What this code does now is locate the paragraph after which you want to add the code. Right now we add the link code after the 5th paragraph. If you want the adds further down the page, you can change the value here from 5 to whatever you need.

$paragraphAfter = 5;

2. It is also important to locate the ads correctly. We have used the content-ads class here to style the ads. You will typically need to add margins, padding or float elements to correctly position the ads. For example, you can use

.content-ads {margin: 10px 0;}

3. Remember to replace the ADSENSE CODE with the code for your account.

4. If you only want to add the code to single posts, change the is_singular (which will add ads to both posts and pages) to is_single.

The credit for the original code goes to Brad Dalton who posted the code on Github. We have modified it a little to suit our needs.


  1. Dean Saliba says:

    Every time I mess with my Function.php file I end up breaking the theme. With that in mind I would suggest a plugin called Ad Injection, which can put ads at the top, middle and bottom of your posts and pages, and can also add an ad into your footer.

  2. Sagar nandwani says:

    Google will automatically inject in your posts up to 3 AdSense blocks. So the first 3 posts (in a top-down order) in your home page or archive pages will have ads.”

    I need this tutorial. Just home page + archive pages will have ads. But 9 post have on home page.

    Blogger default (first 1. post + adsense + 3 posts + adsense + 3 posts + adsense + 2 posts + navi

    But i want ;
    First 3 post + 728×15 adsense + 3 post + 728×15 adsense + 3 post + navigation

    But i cant do it :( Please help me.

    How to make it?

    • Arslan | DailyHow2 says:

      Dude, you need to install custem-designed theme in wordpress in order to get this functionality. Or you can check and install premium theme which offers these feature to show adsense ads on homepage and other pages of your choice.

  3. Tarun Singh says:

    How to insert Adsense ads in blogger ? Please help.

    • P. Chandra says:

      You need to edit the blogger theme template and add adsense code directly where you want it.

      • ORMAXO says:

        but ? if i have more than 3 – 4 post on my home page of than i think it will show 3-4 ads simultanusly ? ….. it may comes under terms of violation ? plz suggest ?

    • d says:

      The solution for putting Adsense ads into blogger can work like this:

      It involves jQuery.

  4. Sunday says:

    Although I would prefer using any Google Adsense Plugin that can easily do this task with just a few click, its still helpful to learn this manual procedure. After all, there are times the plugins may disappoint and this code or manual process would become very handy! Thanks for sharing this piece!

  5. Mark McDougall says:

    Thanks for this. I have been wondering how to do this for a long time. Might try to implement this on my blog once I’ve got my head around it!

  6. friv game says:

    thanks for sharing

  7. WindowsBoy says:

    Thanks for the handy guide. Is it possible to show “Advertisements” or “Sponsors” just above the ad? Also, it would be great if we could show ads only on pages with certain amount of words, say 900 words.

  8. Tahmid Hasan says:

    I am very happy to know this. because I was trying to keep banner in middle of post of my blog site. I think that I can now to do it perfectly thank a lot. Also you can to post in my blog here is my blog site. please visit

  9. valentines day 2014 says:

    thanks for sharing. Might try to implement this on my blog once I’ve got my head around it!

  10. james cameron says:

    amazing post thanks for sharing

  11. Arslan | DailyHow2 says:

    Good article but i prefer to use plugins for this kind of work because you can sometimes, accidently mess code up. And you wouldn’t know how to fix this. So i think it is better to use Quick Adsense plugin for adsense-related stuff.

  12. Kundan Raj Bhattarai says:

    Thanks for the information. But for a non-programmers like us I think wordpress adsense plugins are easier to use. We can easily locate where we want to put the adsense

  13. Rare Subject says:

    This post is very nice. sir tell me more about Google Adsense . and how to improve our blog to increase traffic for Google Adsense. This is my blog check it and give me some tips.

  14. John Tahan says:

    Great information here, I have been an Adsense plublisher for years now, I did make some money in the process way back in 2007-2008. It’s really all about ad placement colors and for me it’s seems that text ads were converting better than picture ads.

    Thanks for the great read

  15. ashish says:

    well i am using a plugin for this i didnt knew about it. thanks for sharing this article . i will surely try this

  16. Saransh Kataria says:

    Any blogger alternative? I don’t want to manually insert in every post

  17. Easter Sayings says:

    Really nice information about google adsense. Please also share some tips regarding grow CPC rate. Thanx for this post.

  18. Vijimuthu says:

    Ya placing the ads in the middle of the post is really useful for increasing the CTR. and also Placing ads in the post starting is another successful method.

  19. Neno says:

    The code works perfectly for Adsense, but if i try to use any other ads code, the function.php breaks.

  20. Manidipa says:

    Hi Chandra,

    CTR is definitely higher in case of in content ads. And you have shared a nice guide on how to do it perfectly. Thanks for sharing.

  21. Mehedi Hasan says:

    Thanks for this helpful and effective tips on how to use adsense code in the content middle. But can it be modified as per just inserting in the middle, not just after specific no of paragraphs. Because all the content doesn’t have the same no of paragraphs or words. Ok thanks again for this code.

Leave a Reply

Your email address will not be published. Required fields are marked *