WordPress Widgets and Google Adsense

I’ve upgraded my blog to use widgets and in the process upgraded a few other things to use widgets too.

I’m using Otto’s Google Adsense widget, it’s working very well.

Except, as you may recall reading here and here, there is an issue relating to the WordPress post preview and Google Adsense that could result in Google blocking your Adsense account.

I’ve not checked to see if the problem has “gone away”, but to be on the safe side, I’ve hacked Otto’s gadsense.php widget to prevent Google Adsense blocks from appearing in the preview. Here’s the code fragment that includes the hack, lines 10 and 12 are the ones to look out for:

[code lang=”php”]
function widget_adsense($args, $number = 1) {
extract($args);
$options = get_option(‘widget_adsense’);
$title = $options[$number][‘title’];
$text = $options[$number][‘text’];
?>

is_preview): ?>


Technorati Tags: , , ,

3 thoughts on “WordPress Widgets and Google Adsense”

  1. Seems like a perfectly reasonable fix to me. However, the is_preview() function is now working in the latest versions of WordPress (definitely in 2.06, not sure about earlier versions), so I suggest using that for future compatibility, in case the method of determining preview status changes (which is entirely possible, given what I have seen on trac).

  2. Thanks Otto. Otto’s suggestion is to replace lines 10 and 12 with the following:

    10.
    11. // Paste your AdSense code here //
    12.

Comments are closed.