Loginskip to content

Archive for June 30th, 2008

Wordpress Adsense Text Widget Fix

Monday, June 30th, 2008

A lot of WP themes are now “widget-ized.” This makes it very easy to customize the navigation areas that normally house components such as Categories, Meta, Archives, Search, Calendar, etc.

When a theme is widgetized, you can simple drag and drop the widgets into the widget editor without having to tweak the theme code directly.

However, one problem is adding Adsense code to a Text Widget. You want to do this because typically you want to a 120×600 tower adsense in that narrow navigation area in the left or right nav bar.

The standard Text Widget, though, strips out the script code of the Adsense block. So to fix this you need to tweak the widget.php code, which you can find in wp-includes directory.

Change this line:

if ( current_user_can(’unfiltered_html’) )
$text = stripslashes( $widget_text[’text’] );
else
$text = stripslashes(wp_filter_post_kses( $widget_text[’text’]

To this line:

if ( current_user_can(’edit_themes’) )
$text = stripslashes( $widget_text[’text’] );
else
$text = stripslashes(wp_filter_post_kses( $widget_text[’text’]

This allows the Text Widget to display script code from your Adsense block.

For more details check out this link:

http://www.thainy.com/2007/05/how-to-use-html-tag-and-script-in-wpmu-text-widget/