How to display Adsense ads only when you want to

Do you ever wondered why some blog don’t use adsense becaue they thing the revenue is too low, while some other are very happy with it? The answer to this question is simple : Adsense work with keywords contained within the page. If the page have keywords that pays well, then you’ll make money, otherwise, your Adsense revenue will not be more than a few cents per day.

Are you still using Adsense ads on your blog? Whatever what you answered to the previous question, if you have an Adsense account, then this trick is for you.

What you need is a WordPress (self hosted) powered blog, an adsense account of course, and some ability to modify WordPress files.

How to do it

First, you have to insert the following code to your function.php file. This file can be found on your theme directory (For example: http://www.catswhoblog.com/wp-content/themes/thesis). If it doesn’t exists, just create it.

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>
    <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>';
}

add_shortcode('adsense', 'showads');

Once you inserted the code and saved your functions.php file, you’ll be 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:

[adsense]

Pros and cons of this method

The obvious good side of this method is that it let you insert your Adsense ads exactly where and when you want it. For example, if you wrote a post about “Making Money Online” you may display some Adsense ads. On the other side, if you wrote a post about WordPress (A keyword that will make you earn just some cents), you shouldn’t display any Adsense.
If you detect that a particular post don’t bring as much as expected, you can remove ads on this post only.

The bad side of this method is that you have to manually insert your ads in each of your posts, and of course, there’s a risk that you forget to do so. Also, if you remove the code from your functions.php file, you’ll have to manually remove the [adsense] codes in your posts.
Also, don’t forget that Adsense terms of services forbids you to use more than 3 ads block per page.

I haven’t started to use this tip on CatsWhoBlog yet, but it gave me good results on some other blogs of mine. Anyways, you have nothing to loose, especially if you decided to drop Adsense from your blog.
Let me know about your questions if any, and your feedback about this method is definitely appreciated!

Related Posts with Thumbnails

13 Comments

  1. Pedro
    Posted October 23, 2009 at 4:51 pm | Permalink

    hey Jean, that sounds VERY good! You are making me wanting to create my own blog :) ))

  2. Posted October 23, 2009 at 7:09 pm | Permalink

    @Pedro : Yes, you definitely should :)

  3. Posted October 23, 2009 at 7:14 pm | Permalink

    Interesting, can you pass variables from a shortcode to this? Would be cool to specify what size of ad you were displaying.

  4. Posted October 23, 2009 at 7:31 pm | Permalink

    @Wes Bos : Yes, you can use attributes with WP shortcode. This can be used to specify ad size, or even a css style. I have this article for you if you want to do how to do it: http://www.wprecipes.com/how-to-use-wordpress-shortcodes-with-attributes

  5. Posted October 23, 2009 at 11:50 pm | Permalink

    That is really cool! it saves having it put on every page, even when you don’t want it there.

  6. Posted October 24, 2009 at 2:36 am | Permalink

    This is a really great tip on the power of shortcodes!

    I’m pretty Godley’s Sniplets plugin can be configured to do this automatically, and insert the the shortcode in the post automatically as well. Just haven’t looked at it lately. I kind of like using the shortcodes directly myself.

  7. Posted October 24, 2009 at 8:31 am | Permalink

    Glad to read that you are enjoying this tip! I’ll write more articles about WP shortcodes if you want to.

  8. Posted November 12, 2009 at 11:52 pm | Permalink

    This is a really handy tip – I didn’t know how easy it is to create shortcodes! Thanks very much.

  9. Posted November 15, 2009 at 7:26 pm | Permalink

    Great tip! A really handy method for adding AdSense ads exactly where you want them.

  10. Posted November 16, 2009 at 8:40 am | Permalink

    Thanks for this tip, sure it will be handy for me. I always try to keep the number of plugins to the minimum and this function will do the job for me.

  11. Posted November 27, 2009 at 1:10 am | Permalink

    Didn’t know it is that easy to create your own wordpress shortcuts, this might be incredibly useful – thanks!

  12. Posted December 23, 2009 at 10:59 am | Permalink

    Thanks for this helpfule article!

  13. Andrea
    Posted April 21, 2010 at 9:08 am | Permalink

    Thank you so much for publishing this article! I spent hours searching the web, trying to come up with a solution to exclude adsense ads from showing on certain pages – unfortunately, nothing worked. Your method however, worked like a charm. :)

    Just a quick question though…I was wondering…will Google ban me for modifying their code? I realize there’s no actual modification taking place when implementing this solution, but will they object to embedding the code in this manner?

    I’m rather new to this whole google adsense thing, so I was hoping if you could please spare a few minutes to clarify this for me? It would be much appreciated!

    Thanks again for the useful info!

    Andrea

13 Trackbacks

  1. By uberVU - social comments on October 24, 2009 at 4:48 am

    Social comments and analytics for this post…

    This post was mentioned on Twitter by catswhocode: RT @tweetmeme How to display Adsense ads only when you want to http://retwt.me/1ljDw...

  2. [...] See the rest here:  How to display Adsense ads only when you want to [...]

  3. [...] Read the original: How to display Adsense ads only when you want to [...]

  4. [...] original here: How to display Adsense ads only when you want to :authors-begin, create-income, income, lead-through, question, revenue, super, technical, [...]

  5. [...] View post:  How to display Adsense ads only when you want to [...]

  6. [...] Read the rest here: How to display Adsense ads only when you want to [...]

  7. By BlogBuzz October 31, 2009 on October 31, 2009 at 12:13 pm

    [...] How to display Adsense ads only when you want to [...]

  8. By Introducing CatsWhoBlog.com on November 9, 2009 at 5:00 pm

    [...] How to display Adsense ads only when you want to [...]

  9. By Introducing CatsWhoBlog.com | Programming Blog on November 9, 2009 at 7:54 pm

    [...] How to display Adsense ads only when you want to [...]

  10. [...] Source: Cats Who Code [...]

  11. By Serious Monday Roundup #18 on November 23, 2009 at 10:01 am

    [...] How to display Adsense ads only when you want to – Are you still using Adsense ads on your blog? Whatever what you answered to the previous question, if you have an Adsense account, then this trick is for you. [...]

  12. [...] Source: Cats Who Code [...]

  13. [...] parler, à savoir comment insérer manuellement un encart google dans chacun de ses articles (source). L’avantage, c’est que vous pouvez alors placer cet espace pub où vous le souhaiter [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting