Post image for How to display Adsense ads only when you want to

How to display Adsense ads only when you want to

by Jean-Baptiste Jung on October 23, 2009 · 25 comments

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!

WPShift

{ 13 trackbacks }

uberVU - social comments
October 24, 2009 at 4:48 am
How to display Adsense ads only when you want to | Angelove
October 24, 2009 at 7:38 pm
How to display Adsense ads only when you want to | Forms Of Profit
October 24, 2009 at 7:48 pm
How to display Adsense ads only when you want to | Bisnis Simpel dari Internet
October 24, 2009 at 8:00 pm
How to display Adsense ads only when you want to — Tip to Make money
October 24, 2009 at 11:00 pm
How to display Adsense ads only when you want to | Blog HYIP Monitor
October 25, 2009 at 6:20 pm
BlogBuzz October 31, 2009
October 31, 2009 at 12:13 pm
Introducing CatsWhoBlog.com
November 9, 2009 at 5:00 pm
Introducing CatsWhoBlog.com | Programming Blog
November 9, 2009 at 7:54 pm
10 Must Have Hacks For WordPress Development | Spyre Studios
November 20, 2009 at 2:22 pm
Serious Monday Roundup #18
November 23, 2009 at 10:01 am
10 Must Have Hacks For WordPress Development | Web Developer
December 4, 2009 at 8:14 pm
Monétiser ses articles avec intégration manuelle d'adsense | NeoSting.net
December 6, 2009 at 2:59 pm

{ 12 comments… read them below or add one }

1 Pedro October 23, 2009 at 4:51 pm

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

2 Jean-Baptiste Jung October 23, 2009 at 7:09 pm

@Pedro : Yes, you definitely should :)

3 Wes Bos October 23, 2009 at 7:14 pm

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

4 Jean-Baptiste Jung October 23, 2009 at 7:31 pm

@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 Tom - StandOutBlogger.com October 23, 2009 at 11:50 pm

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

6 Dave Doolin October 24, 2009 at 2:36 am

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 Jean-Baptiste Jung October 24, 2009 at 8:31 am

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

8 Sebastian Motraghi November 12, 2009 at 11:52 pm

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

9 Indrek November 15, 2009 at 7:26 pm

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

10 George Serradinho November 16, 2009 at 8:40 am

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 Jan November 27, 2009 at 1:10 am

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

12 André December 23, 2009 at 10:59 am

Thanks for this helpfule article!

Leave a Comment

Previous post:

Next post: