AdSense-Deluxe WordPress Plugin
No CommentsLeave a Comment
Last updated: Wednesday, February 23, 2011 | 1726 Views

AdSense-Deluxe is an easy-to-use plugin for WordPress 1.5+ (including WP 2.0) for quickly inserting Google or Yahoo! ads into your blog posts, and managing when and where those ads are displayed. It was developed for my own use after an exhaustive search for a similar tool turned up nothing adequate.

Have you added Google AdSense to your WordPress blog yet? Or maybe thought about it? I was thinking about this last year and knew I could do it generically in the templates, or painfully by pasting the AdSense code into each post I wanted it in, but neither seemed like the optimal way to accomplish my aims. I wanted some flexibility in deciding which posts ads appear in and perhaps some control of which ad format would display in any given blog post.

I found Phil Hord’s AdSense WordPress plugin (http://philhord.com/wp-hacks/adsense) and gave it a test. It’s simplicity was great and it offered some of the control I thought I wanted while avoiding template changes. Phil’s plugin is configured by pasting your AdSense code into the plugin PHP file, then adding an HTML comment (“<!–adsense–>”) anywhere in a post, then your ads are substituted for the placeholder when the post is served. The plugin operates in the common role of a WordPress filter hook.

Working from phil’s simple and effective design, I started digging into the basics of WordPress plugin coding to add some of my the items on my wish list. The first item on the list was having a choice in different AdSense code blocks. It would have been trivial to just put all the different blocks into the PHP code and use a bit of conditional logic for choosing among them, but that’s not very nice for anyone not comfortable mucking about in PHP source code. Which led me to discovering that plugins can have their own configuration pages….Cool!

Introducing AdSense-Deluxe.

AdSense-Deluxe Plugin Download & Version:

Download

Features:

  • Use simple HTML comments for embedding AdSense or Yahoo! Publisher Network ads in a WordPress post
  • Choose from any number of ad styles and format on a post-by-post basis
  • Globally change ad styles
  • Selectively disable display of individual ad styles or all ads
  • Integrated AdSense Preview tool (a sandbox) for seeing what ads will appear on a given page. (Stand-alone AdSense SandBox Tool also available)
  • All settings configured through WordPress Options interface (no knowledge of plugins or PHP required)
  • Easily test different ad formats and color styles across (all, or) a range of blog posts.
  • (Optionally) Apply CSS formatting to the AdSense code.
  • Does not display live ads when editing a page, instead placeholders are shown.
  • Ads are EXCLUDED from RSS feeds — even if you have full-text feeds enabled. (new in v0.3)
  • Preview your ad blocks from the AdSense-Deluxe options page (in case you forget what the ad style looks like), and ads can be clicked without penalty since they use a test account.
  • Support for wp-tiger-admin plugin’s CSS in post/page editor QuickTags

AdSense-Deluxe Advantages and Uses

  • Switching all AdSense ads to a new color scheme across the entire site
  • Trying out image ads instead of textual ads
  • Testing alternate AdSense formats
  • Disabling a class of AdSense ads, or even all ads
  • Including common formatting for AdSense ad blocks (less typing)
  • Testing alternate ad placements for higher click-thru rates
  • Controlling ads within your WP template files.

Usage:

After installation (described later and in the plugin distribution’s readme file) click on the WordPress Admin “Options” link, then select “Adsense” on the sub menu to get to the settings interface. Copy your AdSense code from Google and paste it into the form on the Options page and give it a name. If it’s the style you’ll use most often, just name it “default”. Now you can edit an existing post in your WordPress blog by adding either <!–adsense–> to use whatever you select as your default AdSense format, or by referencing the name you defined, such as <!–adsense#default–>. Now view your post after saving the changes. You should see AdSense ads wherever you inserted the HTML comment.

You can wrap inline CSS styles around your AdSense blocks, or place any other html or strings around, before or after the AdSense JavaScript. For example:

<div style=”display:block;float:left;padding:5px;”>

<script type=”text/javascript”><!–
google_ad_client = “pub-555555″;
google_ad_width = 468;
google_ad_height = 60;
…</script>

</div>

[New in v0.5] To insert any of your defined ad units within template files, you can call a PHP plugin function with the name of the ad unit you want displayed. The syntax is as follows:

<?php adsense_deluxe_ads('my_AdBlock_name'); ?>

However, it’s strongly recommended that you always confirm that the function is available to keep from generating PHP errors or breaking your page display, using the following syntax:

<?php if(function_exists('ad_unit_name')) :
adsense_deluxe_ads('my_ad_unit'); endif; ?>

When you use this new feature it enables the plugin to track the total number of AdSense units displayed on a page and avoid inserting more than the maximum of three units allowed by Google. Sadly, this tracking isn’t completely refined yet and the following example illustrates the issue I still have to code for: Assume you have a single ad unit in a template file, but three ad units in a single post. The plugin tracks the ads displayed for the template and increments the counter by 1. However, replacements are done en masse in a single post, thus the page will now have four ad units displaying (the last of which is going to be blank since Google will not display more than three). The internal counter is now at 4, and if other posts appear on the page they will NOT have any substitutions performed. At some point in the future I will have to rewrite the code to stop doing mass replacements, but for now this is more efficient.

Installation:

» Requires WordPress 1.5+ (including WP 2.0)
» Installed like most all WordPress plugins, just copy the adsense-deluxe.php file into wp-content/plugins
» See the ReadMe.txt file included with the download (before you email me for support!).

Limitations:

» Not technically a limitation, but during testing I noticed that switching which ad format I wanted to use as the default, my browsers continued to show me the old one. This was simply the browser going to its cache for the page. Restarting the browser always resulted in the proper page being shown.
» It currently does no substitutions in WP templates. If users can provide sufficient motivation for doing this, I’ll add it, but right now I prefer managing template-based adsense blocks manually.
» When you click the “edit” link to edit an existing AdSense code block, it’s supposed to scroll the window down to the editing form. This seems to work reliably in FireFox (Mac OS X), but only works half the time in Safari browser. It can be confusing though if you’re not already familiar with the options screen since the page reloads but doesn’t scroll down to show you the form with your data.
» You’re limited to a maximum of 3 AdSense blocks on a single page. If you embed AdSense code into your templates, this counts against the 3 unit maximum, and sometimes Google simply doesn’t have enough ads for your content, so you’ll get empty space in your pages unless you use AdSense’s features for showing alternate ads or folding the empty blocks.

Future Directions:

The current “wish list” I have is geared towards locating the posts in which I have adsense tokens — whether a specific ad block or all ad blocks, and being able to perform mass (and selective) search/replace operations on those posts. It’s simple now to change which ad style is displayed across all the posts where you’re using a named or the “default” ad block, but I’m imagining I’ll (and others) will eventually want to be able to do some house cleaning and review over time.

Something else I just discovered is that I may want to replace an existing ad block which has been in use and contained in various posts, but I’d like to change the name of it to reflect the new style I’m switching it to. In this case, any posts still referencing that named adsense block will no longer get ads displayed since no ad block by that name exists any longer. Ideally, the plugin should update all posts containing that named block with the new name. I do plan on adding features for locating, removing and changing the placeholders within existing posts, but want to approach this very cautiously since mass replacements within the database has the potential of wreaking some havoc…

Release Notes

New in v0.8 2006-06-27
- Fixed bug in “Reward Author” Option. Recommended that everyone upgrade to this version.
New in v0.7 2006-01-10
- Initial support for WordPress 2.0 Rich Editor.
- Minor documentation changes.New in v0.6 2005-12-13
- Bug fixes
- Fixed problem with packaging the zip file under OS X.

New in v0.5 2005-10-03
- Added PHP function for inserting ads into WordPress template files (see ReadMe file for usage).
- Automatic version checking (checks every 7 days for newer plugin versions)

New in v0.4 2005-08-03
- Fixed QuickTag menu display when Tiger-Admin plugin is activated.
- Added preview of your adsense blocks (click the linked Description on any ad block and a window pops up which attempts to display the ads in the style you defined; Note: the ads can be clicked without penalty since they use an adsense test account (”ca-test”).

New in v0.3 2005-08-01
- Fixed problem of AdSense showing up in Full Text RSS feeds.
- Fixed call-time pass-by-reference warnings from PHP.
- No longer “rewarding author” on anything other than Post or Page pages.
- Fixed problem with only two (2) ads being shown on a given page.
- Added AdSense-Deluxe quicktag menu to post editor.
- Stopped showing live adsense in post editing previews; now displays a placeholder
- Added stripslashes() around calls to edit an ad and to display adsense code in posts.
[axodys] reported his ads getting escaped on WP 1.5.3 (with magic_quotes_gpc Off).
- Editing an ad which was disabled causes it to be enabled when saving (fixed).

v0.2 2005-07-28 – Initial (public) release.

Screen Shots:

(clicking any image will open it full size in a new window)

AdSense-Deluxe Options Page Header

AdSense-Deluxe Wordpress plugin Main Options Page

List of defined AdSense-Deluxe Ad Blocks

AdSense-Deluxe Wordpress plugin Ad definitions

AdSense Preview Tool

AdSense-Deluxe Wordpress Plugin Preview Ads

AdSense-Deluxe QuickTag Menu

AdSense-Deluxe QuickTag Menu

Sample Post from this Blog with Multiple AdSense ads

Adsense-Deluxe WordPress Plugin-2 Ad blocks


Closing Remarks:

I hope you find the AdSense-Deluxe as useful as I have over the last year. I look forward to your comments, feature requests and bug reports and will do my best to be attentive to all feedback. Nonetheless, the plugin is offered with no guarantees, warranties, or assurances of any kind, other than the fact that I use it on multiple WP blogs of my own, and have since mid-2005, without any noticeable problems.

If you this plugin helps you earn more from your WP blogs, you’re encouraged to check the option in the configuration screen which “Rewards [the] Plugin Author”… This option uses my publisher ID in 5% of the ads displayed on your site so if someone actually clicks one of those ads, I’ll receive a small commission. It’s fun and helps keep me motivated to release future udpates to this plugin.

Tags: , , ,

Social Bookmark

Comments

There are no comments just yet

Leave a Comment