Insert Google Adsense Anywhere in Your Blog Post

I want to show you how to to insert Google Adsense ads into your post at WordPress blog (or how to show Google Adsense banners anywhere in your post). Google Adsense is one of the most popular way to earn money on your blog. You can see them on WordPress sidebars, in the beginning of the posts or right after the post…

Usually people are using widgets, plugins or inserting them somewhere into single.php file. But this methods not allowing you to show your Google Adsense banners inside your post, for example somewhere between paragraphs or right in the middle of your post. See the example:

Insert Google Adsense Anywhere in Your Blog Post

According to statistics, the best places for your Adsense ads are at the top-left corner of the post and somewhere inside your post, that positions will increase number of clicks (CTR) and will increase your revenue. You know how to do top-left corner, but how to insert Google Adsense ads anywhere in your blog post? Well, it’s easy. We will use WordPress shortcode to embed AdSense anywhere inside your posts.

insert adsense into post

How to Insert Google Adsense Anywhere in Your Blog Post

Creating a shortcode

You need to add the following code into your functions.php file. You can do this in your dashboard, just go to ‘Appearance’ => ‘Editor’ open your functions.php file. Scroll-down to the end of this file and add this code in new line:

function adsenseads() {
    return '<div id="adsenseads">Put your Google Adsense banner code here</div>';
add_shortcode('showmyads', 'adsenseads');

Do it like on my screenshot:

Insert Google Adsense Anywhere in Your Blog Post

Save your changes.

Showing Adsense ads anywhere in your posts

Now you can use this shortcode to insert Adsense into your post, just choose the place in your test and write the following code:


You can use this WordPress shortcode in posts and pages.

Styling Your Banner

Your Adsense banner can be styled in your style.css file, because it is inserted with div element (id #adsenseads). You can add some merges, float parameters, etc.

About Alex Joy

I'm founder and editor of Webdesignzo, architect designer, web designer, graphic designer and SEO optimizer.

64 Responses to Insert Google Adsense Anywhere in Your Blog Post

  1. mintdesignnz says:

    An amazing article. It’s nice to read a quality blog post. I think you made some good points in this post.

  2. getinfonet says:

    Hi, like you blog. Have already implemented internal linking and waiting for related post code. Will now see how I can use the adsense code. Thanks.

  3. Josh Miller says:

    Thanks so much, couldn’t be any easier to follow. Great explanation and screenshot!!

  4. mani says:

    How to enable this in Blogger blog posts..?

  5. Thank you for sharing, this a great way to expand the visibility of your adsence ads.

  6. Sanjeeb says:

    Dear Alex,
    Nice presentation and it is very useful and easy, i loved the way you presented it. Thanks I am able to put ads in between the content, Thanks Alex once again

  7. Anuj says:

    thanks that is nice tip

  8. You each time we write post we have to write [showmyads] in there.

  9. dane says:

    Wooow thankx a lot dude!
    is just what i´m looking for, i have try a lot of adsense pluging but none of then fill my needs….
    thanks for the post

  10. Absolutely brilliant post.

    I just put an Adsense ad in the middle of my blog by following your advise. I now plan to create more such Adsense functions for different sizes.

    Thank you very much.

  11. Alvin says:

    I keep getting an “Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/agtheman/public_html/ on line 67” error when I try to save by functions.php file after adding the code.

    I did a side-by-side with your screenshot, and other than the inclusion of my Google Adsense banner code, it looks exactly the same. Any idea what’s going on here? Is my theme rejecting this functionality, perhaps?Thanks in advance

  12. Chandan says:

    Please do not give wrong directions. It’s not working. Moreover using your code leads to wordpress error denying access to dashboard. Damn.

    • Adam Buller says:

      Hi, did you ever get round this problem? I inserted this code and wordpress won’t let me into my dashboard now, with the errror code aswell!

  13. aprillins says:

    After an hour searching for nothing. Finally, I landed to this post. This post is exactly what I need, a dirty quick guide. But if I can mention, shortcode exec php WordPress plugin would be great If you don’t want to remember all of those shortcodes you made.

    God bless you! I hope you get into the heaven when you kick the bucket. Thanks!

  14. Mark says:

    Thanks for this. Simple but direct to the point.

  15. Is there any way to this for Blogger ?
    ..would love to see that..

    • Alex Joy says:

      it might be, but I dont know the way to do this.

      • Hi, alex,
        I serched few methods after getting inspired by you post.
        I managed to add adsense inside the post for blogger.
        Check this: Example :Adsense inside post for blogger
        what this add_shortcode function does?

        Is it any predefined word press function ?

        • Alex Joy says:

          this code creates a shortcode “showmyads” with function “adsenseads” (this is some kind of “one word link” which will call the function)

          • Dwayne says:

            If I had helped as many people as you have with this one little code, my head would have gotten so big it would have exploded!! YOU ROCK!!!

            Now the question. I want two different styles to place in my posts. Lets say one is where the adsense is text or media, but the other is media only. Is there any way to place another block of code in the functions.php and have a different call function like, [showmyads2] ?

  16. David Z says:

    Super helpful, exactly what I was looking for! Not to mention, works like a charm.

  17. adumpaul says:

    Nice article.Thank you.

  18. Lydia says:


    Your instructions worked fine! I am developing a new web site and your instructions for embedding Google adsense in between posts worked very nicely. Within 10 minutes of pasting there it was.

    One question, however, why when I view the post in which I embedded my new adsense code, my two sidebars do not show up. for my other posts in which I have not embedded adsense between posts, the 2 sidebars show up in excerpt or full view? I appreciate your instructions. Please send me a response. Thanks!
    Post I’m referring to:

    • Alex Joy says:

      I’ve checked your post and everything seems to be ok (I see your sidebars)

      • Lydia says:

        Thanks a lot Alex. I went and studied your set of instructions and finally got it. So, I fixed my ads. Has something to do with excluding the appearance of certain ads like the ones at the beginning or end of posts from your home page, but to show on posts. Then you don’t get a conflict. This is what I believe happened before and I did not understand it.

        Thank you again for taking time to look at my site.

  19. MarkBall says:

    This didn’t work for me. It caused an add, followed by the final line of code, to appear at the top of my dashboard. It also caused an alignment error on my website.
    Can’t think what I did wrong. Maybe it’s just not compatible with my theme.
    Shame. I really wanted this to work

  20. john says:

    Thanks for the nice tip

  21. aufa says:

    What if we want to insert Google ads in the left side of our post?

  22. Very useful post i like it.
    Keep up good work

  23. Ed Johnson, says:

    Great post and best of all, IT WORKS!!!

  24. junnydc says:

    Wow, I can modify php code to add adsense with ease. but this one really “ROCKS”. You can put anything in that fuction mate like adding a chitika or other message. Thanks for the info.

  25. Thank you for your post. Very easy to understand tutorial. Use it inside my posts now. Works great!

  26. Paul says:

    Thanks for sharing this WordPress hack/tutorial. Very helpful and handy.

  27. Mark says:

    I tried added the code but it comes up with an error. The file you mentioned to add it to seems like it has different script then the one I am opening up. Could there be another functions.php script I need to add this to?

  28. Very nice article… proved very helpful to me !! :) keep updating. such kind of posts help newbies a lot

  29. Thanks, I’ve been looking for something like this. I sort of did know that the Adsense code was manually pasted on the post because it seemed like some of the good bloggers had it on perfect parts of their blog posts. :)

  30. Trung Nguyen says:

    It means we have to edit all of our blog posts???? I don’t think we all like to do that so, any else way?

  31. Jon Page says:

    hi can you help me modify this code… it didnt work on my theme… thanks

  32. Tayler says:

    Thanks for the tip. It’s helpful for my web design :)

  33. Chigozie says:

    Pls i want my google ad to show in the middle but it cant get it to work; pls help

  34. James says:

    I have tries a lot of tips on how to get adds in between my posts but this one is just on point.

  35. Ewan says:

    thanks dude for this tutorial..
    after struggle with numbers of plugin,
    now I can add adsense anywhere in my post without using any plugin..

  36. Ankur Dubey says:

    this is the easiest way
    thanks for the sharing….

  37. jai says:

    explain how get multiple types of ads . means how do paste different ads between content admin please explain and how to align that

  38. thanks man! what a great way to achieve this, the only thing I would say is do you think it is possible to add it to every post without adding the shortcode?

  39. Untara says:

    that tips is what i’m looking for. Its very helpful.
    I’m beginner for adsense. thanks again

  40. emmma says:

    Stupid poisonous code, dangerous code, site giving error and no way to get rid of this error.

  41. Thanks for this piece of article on how to insert adsense inside wordpress blog. Am giving a try now. kindly keep it up. Thumb UP

  42. NIce tutorial, Thanks a lot. I’ve used this in a news portal to display ads inside news content.

  43. Acquin says:

    Awesome Stuff!! Finally i got something working!! Thanks a lot!!

  44. Dickson says:

    Thanks for the great sharing, My adsense CTR is very low now. I will try your method.

  45. Jane says:

    Thanks for the great post.
    After i have added in the codes, the ads does appear at the post. However, the following:
    ‘; } add_shortcode(‘showmyads’, ‘adsenseads’);
    also visible at the website.

    What have i done wrong?

  46. GIrdhar says:

    Nice, I have tried and its running well,

    Thanks buddy… pls also post the auto showing ads like that without inserting this shortcode… thanks

  47. Matt says:

    Great article…helped me out a lot. Thank you so much.

  48. Kumar says:

    Hi Alex,

    Thanks for the code, it works.

    I have been using QUICK ADSENSE plugin but i noticed that ad impression is different in Manually added code and plugin. And the most important thing is during last 45 to 50 days overall income was goes down. I have removed this plugin from one of my website and added manually and just after a day overall income has increase by 20%.

    Thanks you again for sharing this code – it works with my wordpress page.

  49. michael says:

    Now I am doing it in my blog. Thanks a lot for an idea.

  50. telugu says:

    Thank you, It is working.

Leave a Reply

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