{"id":493,"date":"2007-01-05T02:49:02","date_gmt":"2007-01-05T01:49:02","guid":{"rendered":"http:\/\/www.craigmurphy.com\/blog\/?p=493"},"modified":"2007-01-05T02:52:11","modified_gmt":"2007-01-05T01:52:11","slug":"wordpress-widgets-and-google-adsense","status":"publish","type":"post","link":"http:\/\/www.craigmurphy.com\/blog\/?p=493","title":{"rendered":"WordPress Widgets and Google Adsense"},"content":{"rendered":"<p>I&#8217;ve upgraded my blog to use widgets and in the process upgraded a few other things to use widgets too.<\/p>\n<p>I&#8217;m using <a href=\"http:\/\/ottodestruct.com\/blog\/2006\/04\/09\/fun-with-widgets\/\">Otto&#8217;s<\/a> Google Adsense widget, it&#8217;s working very well.<\/p>\n<p>Except, as you may recall reading <a href=\"http:\/\/www.craigmurphy.com\/blog\/?p=252\">here<\/a> and <a href=\"http:\/\/error.wordpress.com\/2005\/12\/27\/adsense-on-wordpress-20\/\">here<\/a>, there is an issue relating to the WordPress post preview and Google Adsense that could result in Google blocking your Adsense account.<\/p>\n<p>I&#8217;ve not checked to see if the problem has &#8220;gone away&#8221;, but to be on the safe side, I&#8217;ve hacked Otto&#8217;s gadsense.php widget to prevent Google Adsense blocks from appearing in the preview.  Here&#8217;s the code fragment that includes the hack, lines 10 and 12 are the ones to look out for:<\/p>\n<p>[code lang=&#8221;php&#8221;]<br \/>\nfunction widget_adsense($args, $number = 1) {<br \/>\n\textract($args);<br \/>\n\t$options = get_option(&#8216;widget_adsense&#8217;);<br \/>\n\t$title = $options[$number][&#8216;title&#8217;];<br \/>\n\t$text = $options[$number][&#8216;text&#8217;];<br \/>\n\t?><br \/>\n\t<?php echo $before_widget; ?><br \/>\n\t<?php $title ? print($before_title . $title . $after_title) : null; ?><\/p>\n<p><?php global $wp_query; if (!$wp_query->is_preview): ?><\/p>\n<div class=\"adsensewidget\"><?php echo $text; ?><\/div>\n<p><?php endif; ?><\/p>\n<p>\t<?php echo $after_widget; ?><br \/>\n<?php\n}\n[\/code]\n\nHopefully Otto won't take offence to this quick fix - I'll do some more research later on today after I've grabbed some sleep - it could well be that the problem has been fixed.<p>Technorati Tags: <a href=\"http:\/\/technorati.com\/tag\/Google+Adsense\" rel=\"tag\">Google Adsense<\/a>, <a href=\"http:\/\/technorati.com\/tag\/WordPress\" rel=\"tag\">WordPress<\/a>, <a href=\"http:\/\/technorati.com\/tag\/Widgets\" rel=\"tag\">Widgets<\/a>, <a href=\"http:\/\/technorati.com\/tag\/preview\" rel=\"tag\">preview<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve upgraded my blog to use widgets and in the process upgraded a few other things to use widgets too. I&#8217;m using Otto&#8217;s Google Adsense widget, it&#8217;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 &hellip; <a href=\"http:\/\/www.craigmurphy.com\/blog\/?p=493\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">WordPress Widgets and Google Adsense<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-493","post","type-post","status-publish","format-standard","hentry","category-general"],"_links":{"self":[{"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=493"}],"version-history":[{"count":0,"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/493\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=493"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.craigmurphy.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}