The other day I signed up for the Google AdSense program. No problem integrating the AdSense code into static pages here or there. WordPress was a different matter. I could add code manually in templates but adding it to posts didn’t go over so well. WordPress applied formatting to the AdSense code which broke things.
I came across Phil Hord’s plugin. I liked the idea of the
<!--adsense-->content tag. But it offered no way to configure the ad code without editing the plugin code. It offered no template tag either but that could be easily changed. Well into the development of the second incarnation of this plugin I learned about AdSense-Deluxe. I didn’t try it since my own work was far enough along that I was interested in seeing it through. I did notice the content tag format and picked up on that idea.
I decided to spend a few long nights and excercise my php skills. The first cut worked but the concept had flaws. I tried to understand the meaning of the AdSense code and assemble the AdSense code block from configurable options. While it resulted in a working plugin, it had some major design flaws. It would have been quite awkward to extend the options administration page to support multiple saved ad code blocks. I also learned that its use might violate Google program policies by generating the AdSense code.
A new idea and redesign was in order. What I came up with is a way to save different ad code blocks including a name and description. The proper way to obtain these ad code blocks is by generating them on the Google AdSense site, then copy and paste them into the AdSense Manager plugin. The ad blocks are inserted into posts or pages using the
<!--adsense-->tag. The
adi_asm_ad()function is provided to place code blocks in templates. Ads can be enabled and disabled on a per post and per page basis via a custom field and on a global basis.
The installation of this plugin will create two additional database tables, one holds the ad information, the other holds plugin options.
Installation:
- Tested with WordPress version 1.5.2
- Copy the
adi-adsense-manager.php
file into thewp-content/plugins/
directory - Activate Adi’s AdSense Manager in the plugin panel
Usage:
In templates use
<?php if (function_exists(adi_asm_ad)) adi_asm_ad(); ?>. The
adi_asm_ad()function supports a number of optional arguments
adi_asm_ad([name],[id],[pre],[post],[quiet])where
name - Ad name
id - Ad id
pre - HTML displayed immediately before ad
post - HTML displayed immediately after ad
quiet - No error or warning messages output
In posts or pages use the
<!--adsense-->or
<!--adsense?[name]-->tags. The
<!--adsense-->tag inserts the default ad. The
<!--adsense?[name]-->tag insterts the named ad.
Per post or page ad content is controlled by the
adsense_enablecustom field. If a custom field
adsense_enableexists and is set to ‘no’, ‘false’ or ’0′ ads are disabled.
Wishlist:
- Popup window with ad preview
- Quicklink button
Download:
History:
- First cut for public release.