This is the Simple AdSense plugin for WordPress by PRmoney.com, based on work done by Elad Salomons.
It has been tested and is compatible with WordPress version 2.5.
If you’re looking for one that works with MP MU, you can download it from this post:
http://g2y.net/blog/2008/05/11/adsense-share-mu-plugin-version-122/
Simple AdSense has options for your AdSense Publisher ID, channel, and search channel to allow you to better track where your AdSense revenue is being generated.
Download:
Download the latest version here:
Simple AdSense Plugin version 1.0
Installation:
Installation is simple. Just upload it to your WordPress wp-content/plugin directory, then activate it by logging into your blog as admin and click on the “Activate” action link on the Simple AdSense plugin row:

Once you’ve activated it, click on the settings link, and then click on “Simple AdSense” to configure the settings :

All you are required to enter is your AdSense Publisher ID. The Channel and Search Channel are completely optional and are only included to better track your AdSense revenue.
NOTE: Google has started using Ad Slots as well as Channels. They are not the same thing. You must enter your AdSense Channel ID in order for Simple AdSense to work correctly. The channel ID can be found in your Google AdSense Channel settings: https://www.google.com/adsense/channels
Usage:
The themes on G2Y are already customized for use with the Simple AdSense Plugin, so there’s nothing more to be done for them- just download & install the theme and then download & install the Simple AdSense plugin.
You’ll need to have decent knowledge of CSS, HTML, and PHP in order to implement the actual AdSense ads into an existing template that is not found on G2Y. Feel free to send an email to support@g2y.net if you’re not up to the challenge, and we’ll update your template for you. The only caveat is that we will add your template to G2Y site for others to download for free, so be sure you have the rights everything in your template.
If you’re feeling brave, these instructions should help you get started:
The only function you should be concerned with is called get_adsense_code. It’s used in your theme like so:
if(function_exists('get_adsense_code')) {
list ($adsense_code,$adsense_channel,$adsense_search_channel,$adsense_owner)=get_adsense_code();
}
get_adsense_code will retrieve the Simple AdSense settings from the database and return them in an array. The variables returned should be self explanatory, except for adsense_owner. You can ignore that one, it was left in for compatibility with the WP MU version of Simple AdSense - AdSense Share MU.
In order to make the most efficient use of your blog, it’s highly recommended to store the Simple AdSense variables in global variables. That will allow you to use them in other parts of your theme without having to query the database every times an ad is displayed. The way I do that in all G2Y AdSense-ready templates is to pre-define the variables as globals (before calling the get_adsense_code function) in the header.php file like so:
global $adshown,$adsense_code,$adsense_channel,$adsense_search_channel,$adsense_owner;
$adshown=0;
$adsense_code='';
$adsense_channel='';
$adsense_search_channel='';
You’ll notice a new variable there called ‘adshown’ . That is used to keep track of the number of Google AdSense Ad Units on one page. The AdSense TOS only allows for three Ad Units per page, so this variable is used to track the number of times Ad Units are displayed on a page. I believe Google’s AdSense code is smart enough to stop displaying Ad Units after the third one, but there’s no reason to make them think you’re trying to break the rules, now is there?
Once you have your variables, it’s a simple matter of using them in your AdSense code:
<script type="text/javascript"><!--
google_ad_client = "<?php echo $adsense_code; ?>";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_channel="<?php echo $adsense_channel; ?>";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "A6000C";
google_color_text = "000000";
google_color_url = "A6000C";
google_ui_features = "rc:0";
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Simple AdSense uses google_ad_channel IDs, not Ad Slots! Google has added the ability to quickly change the Ad Unit design (Ad Slots), and it’s hard to locate the older code used in the above example, which utilizes Ad Channels. Feel free to download some themes to see various examples of what I’ve done.
Next, Don’t forget to increment the adshown counter:
<?php
$adshown++;
} ?>
The whole thing looks like this in my template’s headerads.php file:
<?php
global $adshown,$adsense_code,$adsense_channel,$adsense_search_channel,$adsense_owner;
$adshown=0;
$adsense_code='';
$adsense_channel='';
$adsense_search_channel='';
if(function_exists('get_adsense_code')) {
list ($adsense_code,$adsense_channel,$adsense_search_channel,$adsense_owner)=get_adsense_code();
}
<script type="text/javascript"><!--
google_ad_client = "<?php echo $adsense_code; ?>";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_channel="<?php echo $adsense_channel; ?>";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "A6000C";
google_color_text = "000000";
google_color_url = "A6000C";
google_ui_features = "rc:0";
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<?php
$adshown++;
} ?>
I’ve found that it’s easier to create a new .php file when modifying existing templates, then just add an include where you need them in the main template. That way upgrades are simple. In this case, I added headerads.php to the template’s header.php file:
<div id="header">
<div id="headerads">
<?php include ("headerads.php"); ?>
</div><!-- headerads -->
<div id="heading">
<h1><a href="<?php echo get_settings('home'); ?>/"><u><?php bloginfo('name'); ?></u></a></h1>
<div class="description"><?php bloginfo('description'); ?></div>
</div><!-- heading -->
</div><!-- header -->
You’ll notice the use of the new div. That is defined in CSS and controls the location and some of the colors. (The rest of the colors are in the AdSense ad itself.)
For the other ads in the template, the code looks just like it does above, without the call to the get_adsense_code function, since the variables are now globals.
There are some other tricks I use in most, if not all, G2Y AdSense-ready templates. One of which is to display an inline ad randomly after blog entries. The code to do that looks like this:
<?php if (have_posts()) : ?>
<?php $AdLoc1=rand(1,4); $AdLoc2=rand(5,8); $AdLoc3=rand(9,12); $CurLoc=0; ?>
<!-- Random ads will be shown after posts <?php echo "$AdLoc1,$AdLoc2, & $AdLoc3"; ?> -->
<?php while (have_posts()) : the_post(); ?>
<div class="post-wrapper">
<div class="date">
<span class="month"><?php the_time('M') ?></span>
<span class="day"><?php the_time('j') ?></span>
</div> <!-- date -->
<span id="post-title" class="titles">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a>
</span>
<div class="post">
<?php the_content('Read the rest of this entry »'); ?>
</div> <!-- post -->
</div> <!-- post-wrapper -->
<div class="post-footer">Posted in <?php the_category(', ') ?>
<strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?>
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
<?php
$CurLoc++;
if($CurLoc==$AdLoc1 || $CurLoc==$AdLoc2 || $CurLoc==$AdLoc3) {
include (TEMPLATEPATH . '/post_ad.php');
}
?>
<?php comments_template(); ?>
<?php endwhile; ?>
You can see that I’ve added three AdLoc variables in the middle of the have_posts/the_post while loop, as well as the CurLoc variable to keep track of what post is being displayed. If CurLoc matches the random AdLoc1, 2, or 3 number, the ad will be displayed by including the post_ad.php file. (I won’t get into it’s content here. Feel free to download any G2Y AdSense-Ready template and poke around to see what I’ve done.)
There is an if statement inside post_ad.php that will only display the add if adshown is less than 4. It also increments the variable when an ad is displayed.
Closing Thoughts:
That hardest part of modifying an existing template for use with AdSense is dealing with the messy code found in almost every template out there. It takes me anywhere from 30 minutes to several hours to fix all the CSS bugs and them implement the AdSense ads in the most profitable locations of the template.
I’ve also found that template authors don’t usually bother to actually test their templates to ensure they display properly in FireFox & Internet Explorer (6 & 7!), nor do they bother testing various other aspects of their templates, like the widgets, tag cloud, calendar, etc. Every template on G2Y has been thoroughly tested, but I’m sure I’ve missed something. Don’t hesitate to email support@g2y.net with bug reports.
Comments Off