DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

Do you ever wanted to get a total control over the way your adsenses ads are displayed? In the following recipe, I’m going to teach you how to be able to use adsense only in the post you want and display the ads where you want.

First, you have to add the following code to your function.php file. Don’t forget to change the adsense code, unless you’d like to display my ads on your own site 😉

function showads() {
    return '<script type="text/javascript"><!--
google_ad_client = "pub-3637220125174754";
google_ad_slot = "4668915978";
google_ad_width = 468;
google_ad_height = 60;
<script type="text/javascript"

add_shortcode('adsense', 'showads');

Once you saved the functions.php file, you’re now able to embed your adsense code on your posts and display it exactly where you want. To do so, simply paste the following code on the editor, in html mode:



  1. Great share !

  2. please i don’t know how to locate the end of the php in my function.php file.

  3. How do i put it side by side with content?

  4. Nice post dude. Till now am using plugin for this but this tiny code is working great. Keep up

  5. nice work, but i have some questions :-
    1) How to align the ads to center ?
    2) How to use multiple ad sizes ?

    Hope you ll answer these ques soon

  6. @Ramandeep Singh

    1) To align the ads to center use this code:

    function showads() {
    return ‘ADSENS CODE


    add_shortcode(‘adsense’, ‘showads’);

    2.) multiple ad sizes exemple 1

    function showads() {


    add_shortcode(‘adsense728x90’, ‘showads’);

    And paste the following code on the editor, in html mode:


    multiple ad sizes exemple 2

    function showads() {


    add_shortcode(‘adsense468x60’, ‘showads’);

    And paste the following code on the editor, in html mode:


  7. Make sure your functions.php file isn’t capitalized! (Functions.php) Otherwise you’ll drive yourself crazy and your shortcode won’t work!

  8. This works great. Now how to text wrap it?


  9. Thanks a lot this post helped to hire some authors for my blog based on adsense revenue sharing. You guys are truly awesome, and it means a lot to me.

  10. thanks! helped me a lot

Leave a Comment

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