29.04.2010 in Home > Internet > Adsense > WordPress by Namit Gupta 18

Manually implement Google Adsense Revenue Sharing in your WordPress Blog

Revenue SharingRevenue sharing could be implemented in a multi-author blog to pay guest authors for their efforts. Sometime back I implemented this on MightyLaws, my another blog which I founded 4 months ago and have been administering it since then. Its a LAW related blog, Which aims at Simplyfing the “Mighty Laws”.

Coming back to the point How to Manually Implement Google Adsense Revenue Sharing in your blog.

What differentiates each Adsense unit is “google_ad_client” and “google_ad_slot” values apart from the ad unit size. So we’ll add two new text fields to WordPress User Profiles, client and slot for each author to put his Adsense ad_client and ad_slot value in his/her user profile.

We’ll then code the Adsense unit to take ad_client and ad_slot values from the particular post author’s profile on whichever post it loads on. So the Adsense code will automatically change with the post author.

Procedure to add Revenue Sharing functionality to a Multi-Author WordPress Blog

1.) Firstly we’ll Add two new text fields to user profiles, client and slot.

Add the following code to the functions.php file in your theme folder, head-over to WordPress Dashboard>Appearance>Editor>functions.php or do it via ftp.

function add_adsense_contactmethod( $contactmethods ) {
$contactmethods['client'] = 'client';
$contactmethods['slot'] = 'slot';
return $contactmethods;
}
add_filter('user_contactmethods','add_adsense_contactmethod',10,1);

Two new fields have been added to the user profiles

adsense-client-slot

Users can now enter their own “google_ad_client” and ”google_ad_slot“ values in their profile.

Note: Enter the default ad_client and ad_slot values in the client and slot field, in case a user does not have Adsense verified account default ad unit will be displayed. Otherwise no ad unit will be displayed on the user’s post(s).

2.) Now we’ll edit the Adsense unit code to take google_ad_client and google_ad_slot values automatically from the author’s profile.

Replace the google_ad_client value with

<?php the_author_meta('client'); ?>

and google_ad_slot value with

<?php the_author_meta('slot'); ?>

It should look like:

<script type="text/javascript"><!--
google_ad_client = "<?php the_author_meta('client'); ?>";
/* 468x60 */
google_ad_slot = "<?php the_author_meta('slot'); ?>";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

This ends the procedure. Each post in your blog will now display Adsense unit of the particular author it belongs to.

You have successfully implemented Adsense Revenue sharing in your WordPress blog. Feel free to comment-in your query or doubts, I’ll be happy to answer them.

Also see: Implement Google Adsense Section Targeting in your WordPress blog

Related Articles

  • http://www.shoutmeloud.com Harsh Agrawal

    Good tip Namit. Seems like you getting your hands dirty with codes. Keep up good work. I use adsense revenue sharing plugin and recommend that for people who are not coder.

  • http://www.theitechblog.com Namit Gupta

    Thanks Harsh. :) I have a deep interest in coding. I spend more time tweaking my blog than on writing posts. :) I love designing and development work.

    As you have said, plugins are good for people who are not coder but as they are heavy on resources I recommend not using much of them.

  • http://www.imgzzz.com/ Ayaz Malik

    Hey,
    is it necessary to add ad_slot ? or it can work with just publisher id ?

    • http://www.theitechblog.com Namit Gupta

      It is necessary to add both the ad_slot and ad_client, else ads wont be displayed.

      • http://www.imgzzz.com/ Ayaz Malik

        al right actually i launched my new site , its a free image hosting/sharing with revenue sharing
        so workign on it. yes seems its working good
        thx alot

        • http://www.theitechblog.com Namit Gupta

          My Pleasure. :) Checked you website. Its a brilliant concept. But may violate Google AdSense Programme Policies, "placing images next to individual ads…"

  • http://bajar-de-peso-rapido.blogspot.com Caroline

    That's a nice Idea but I'm a bit scared to practice it. This process won't be too good for new publishers because click fraud might occur and your account will be terminated.

  • http://financetrain.com/ FinanceTrain

    There is a problem with the above code. Yoyu have only one slot id from each author. So, if you are displaying two ad units on a page, both will contain the same slot_id. As per google, each ad has a unique slot id, even if it is from the same publisher.

    • http://www.theitechblog.com Namit Gupta

      Yes, only a single ad unit can be displayed using the above code.

      For multiple ad units you can repeat the steps mentioned in the post and change the variable name 'client' and 'slot' to 'client1' and 'slot1' everywhere in the mentioned code. Use a different variable name each time you repeat the steps.

      Do share your experience after doing it.

  • http://z3olyte.com Cindy

    this seems good.. I successfully implemented the ad slot and client values on my profile page, but my test ad isnt showing up on my post. I injected the adsense code inside the html post editor. I have separate adsense codes on my sidebar but I placed the guest ad on top so it loads first but its not showing. Where exactly should I paste it?

    • http://www.theitechblog.com Namit Gupta

      You are putting the code at the wrong place, the code is not to be put in the html post editor.

      Goto Dashboard->Appearance->Editor

      Then Single Post(single.php)

      and paste the code wherever you want the ad to appear.

  • http://www.featuredcontentonline.com Norman

    Hi there,

    First off I really want to thank you for putting these instructions out there, I’ve been searching high and low for this.

    I was able to add the two new fields into the user contact info, but when I add the code into the adsense blocks no adds are appearing. I’m using the ‘adsense integrator’ plugin. Here’s the code I’m using…

    <!–
    google_ad_client = "”;
    /* 336×280, created 10/20/10 */
    google_ad_slot = “”;
    google_ad_width = 336;
    google_ad_height = 280;
    //–>

    I’m using the WP Genius theme.

    Any ideas why this isn’t working?

    Thanks in advance for any help you can offer,

    Norm

  • http://www.featuredcontentonline.com Norman

    I’m not sure why the code isn’t appearing here so I published this on my blog…

    http://www.thecheapbastid.com/2010/11/google-ad-code-problem/

  • shankar

    Hi,
    but is it legal according to google’s terms?
    because google website says we should not alter code in anyway.
    we are altering code or content in code here.
    is it legal anyway?
    have you asked google this?
    please tell..
    Thanks

    • http://www.theitechblog.com Namit Gupta

      Yes, Google Adsense restricts its publishers to alter the Ad code. But we are not altering the adsense code in any way that is illegal or with any bad intention. We are just making it more dynamic to display ads according to the post’s author. All muti-author revenue sharing blogs does the same, and are running well. So this can be done, it is not illegal.

  • http://www.articleplot.com Brian

    That is some pretty awesome stuff. Revenue sharing is a great if you can build up some good writers.

  • http://www.reviewsaboutanything.com Jay

    Hi,

    Firstly, thanks for the great post, I’ve been searching for ages trying to find a quick way to do this and your explaination has been just that.

    Secondly, Is it possible to have the adsense shared between owner of the site and the author. In otherwords, instead of showing the authors ads all the time on their articles, is there a way to show my ads 50% of the time and their ads 50%.

    I’m useless at coding, so any advice or pointers will be great.

    Thanks in advance.