WordPress 2.0 problems for google adsense users, and a workaround


As just another reason to not upgrade to WordPress 2.0 (or even install it in the first place for now), it’s been widely reported that WP 2.0’s live preview feature causes serious problems for those bloggers who utilize Google’s Adsense to monetize their blogs.

Lunacy Unleashed has a great article on dealing with the adsense problems in WordPress 2.0 dealing with the adsense problems in WordPress 2.0, as well as a few workarounds.

In sum, the problem stems from the fact that the live preview will try to fetch your google adsense ads, even if your post has not yet been published. This can be seriously problematic, as when google tries to determine appropriate contextually relevant ads for the page, it receives a 404 (page not found) error because the page does not yet exist. At a minimum, this could result in ads that aren’t relevant to the content on your page. At it’s worst, it could result in your adsense account being suspended, “since Google prohibits displaying ads on 404 pages”.

Not good.

Michael Hampton’s post provides details on how to get around this problem by modifying your template code (which beginning WP users are probably not so comfortable doing..) to put in a check to see if the what’s being displayed is a preview, and if so not display AdSense ads using the following code:

// Paste your AdSense code here //

Unfortunately, this workaround still results in multiple problems, the first one being that there is a known bug with the is_preview() function in WP 2.0. Furthermore, the abovementioned code only works ‘inside the loop’ (see Matt Read’s post for help in understanding “the loop”, as well as the information on The Loop in the wordpress codex)

Michael suggests yet another workaround for those who want to place their ads outside the loop (a common occurence) in the form of the following code:

is_preview): ?>
// Paste your AdSense code here //

HOWEVER, because of the problems with the is_preview function being quirky in WP 2.0, these workarounds don’t always work and in the words of EUGENIUS, “It looks like until is_preview is fixed, don’t put adsense on the WordPress (2.0) blog.”

To me, I find this unbelievably unacceptable -with the given propensity for the majority of bloggers these days to utilize Google AdSense ads on their blogs, I simply cannot understand how it is possible that this was not resolved prior to WordPress 2.0’s being released, and is reason alone not to use it (never mind upgrade your existing installations to WP 2!) And shouldn’t there be a simple checkbox to just turn live preview off for those of us who would rather have AdSense ads working on our site than see a live preview of our post?? How hard would that really be?

3 thoughts on “WordPress 2.0 problems for google adsense users, and a workaround

  1. I’ve been using live preview on my account for around 6 months (I think) and my adsense or YPN hasn’t been deactivated. My earnings have only gone up too. I don’t think it’s worth getting so excited over a theoretical problem. If someone actually affected, then make an issue of it.

    Also, as I told Michael on IRC, another easy workaround for this is to check if the current user is the admin, and not show the ad then.

  2. Hi Matt,

    Thanks so much for responding to my post (I’m genuinely honored that you’re even reading any part of my blog :)

    I’m thrilled to hear that there is another workaround for the adsense/live preview issue. Since Michael didn’t post it, and for those of us who aren’t as familiar with the code behind the scenes, could you kindly provide an exact codeblock for how one would encorporate the workaround that checks if the current user is the admin in which case the ad would not be shown? This way I can not only encorporate it on my own WP 2.0 blogs and report back on the experience, but I can also show my blog readers how to apply the workaround, as well. If the code differs dependant upon whether it is in the loop or not, can you provide both code examples? I would greatly appreciate it.

    Thrilled to hear your earnings have only gone up — that’s great news! I hope the same holds true for me once I start doing more WP 2.0 blogging.

    And to address the making a stink about the issue prior to knowing anyone whose account actually was deactivated – I think it is somewhat warranted in that some people rely on their adsense revenue to get by (if not as a sole source of income for them) and once your account is revoked, there’s no going back — so to wait until Google notices that you’re breaking their TOS and deactivates your account is a scary proposition. I hope you can see where I’m coming from on that.

    Looking forward to hearing back from you.

  3. here are some ways to overcome the is_preview flackyness:

    Check the post status:

    global $posts;
    if ($posts[0]->post_status != “draft”) {
    … do ads here …

    Or, similar to what Matt said, check if the user is author. (You don’t need to see your own ads anyway).

    global $posts, $current_user;
    if ($posts[0]->post_author != $current_user->ID) {
    … do ads here …

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>