UPDATE: How to Blog has MOVED! Please update your bookmarks and feeds! The new address is :
http://www.emilyrobbins.com/how-to-blog/
and all new posts and post updates will be made there! Comments and trackbacks at this location are now closed -- please visit the new How to Blog site in order to add a comment or a trackback and see updates to existing posts as well as all new posts from this point forward!

« OFF-TOPIC: Hey Ladies! Now you can carry your laptop around IN STYLE thanks to Mobile Edge | Main | Why I'm not upgrading to WordPress 2.0 - for now »

January 10, 2006

WordPress 2.0 problems for google adsense users, and a workaround

THIS POST HAS BEEN MOVED TO:

http://www.emilyrobbins.com/how-to-blog/wordpress-20-problems-for-google-adsense-users-and-a-workaround-314.htm

Please update your bookmarks to reflect the new, permanent location of How to Blog.  Comments and trackbacks on this post are now closed.  If you wish to comment on this post, please visit the new site!  Thank you!

-----------------------------------------------------------------------------------------------------------------------

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:

<?php if (!is_preview()): ?>
// Paste your AdSense code here //
<?php endif; ?>

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:

<?php global $wp_query; if (!$wp_query->is_preview): ?>
// Paste your AdSense code here //
<?php endif; ?>

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?

January 10, 2006 in Weblogs, WordPress | Permalink | Email This Post

Bookmark with del.icio.us, add to Yahoo!MyWeb or Digg This!

Comments

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.

Posted by: Matt | Jan 11, 2006 12:45:47 AM

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.

Posted by: Emily from How to Blog | Jan 11, 2006 1:33:12 PM

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 ...
}

Posted by: Matt Read | Jan 11, 2006 11:20:59 PM

Thanks, this is gret information for those of us who are using Wordpress 2.0. Do you mind telling me exactly WHERE in the template I would need to paste the above code that checks if the user is the author?

Thans=ks again!

Posted by: Marcia | Jan 19, 2006 11:09:54 PM

Ok, I admit I've been into Word Press just about long enough to have broken my share of templates. Is this a true issue or something like while standing on your head on Tuesday kind of upside down and backwards you might trip the wrong attribute in your MySQL table that reverses the polarity of the universe and causes a 400 page lighting bolt to strike from the skys of the Google editors whom perish your account from this world and the next. Look, maybe this is a silly assumption but I figure the editors over at Google are aware of this problem and will not banish you from the world of the living on account of some accident of missplaced code... But just in case I'm wrong I've install 2.0 on one account and kept 1.5 on the other. In the event the worse case scenario plays out and one should suddenly find themself banished to the underworld of Yahell, or assimilated by the undead of the Bill Gatius Borg, I'm not going to miss a few Adsense dollars... It might even motivate me into landing a real job... If anyone has a flashlight and a map out of this black hole hotel California:)

Posted by: Lucky7Star | Jan 20, 2006 1:08:13 PM

I don't believe this is a problem. Question, are there any adsense ads placed on a 404 page. Answer No. I agree that the google bot gets a 404 error, but the bot finds no ads to serve. No ads, no violation. Simple as that

Larry

Posted by: Mr Blogmeister | Jan 31, 2006 10:55:07 AM

The comments to this entry are closed.

UPDATE: How to Blog has MOVED! Please update your bookmarks and feeds! The new address is :
http://www.emilyrobbins.com/how-to-blog/
and all new posts and post updates will be made there! Comments and trackbacks at this location are now closed -- please visit the new How to Blog site in order to add a comment or a trackback and see updates to existing posts as well as all new posts from this point forward!