Creating an empty/blank text widget for WordPress without additional markup and divs
WordPress provides a simple text widget that you can use on your blog to add some random HTML, Ads, images, and so on. But I have one problem and that is that it’s always adding some extra HTML like this.
<div class="widget"> <div class="textwidget"> </div> </div>
Sometimes you do not want this code if you for example want to add a widget to a ul and want the outer tag to be a li. I tried to Google for this but surprisingly I didn’t find a single “Super Empty Text Widget” so I created one myself.
/**
* SuperEmptyWidget Class
*/
class SuperEmptyWidget extends WP_Widget {
/** constructor */
function SuperEmptyWidget() {
parent::WP_Widget(false, $name = 'SuperEmptyWidget');
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
extract( $args );
$content = $instance['content'];
echo $content;
}
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['content'] = $new_instance['content'];
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$content = esc_attr($instance['content']);
?>
<p>
<label for="<?php echo $this->get_field_id('content'); ?>"><?php _e('Content:'); ?></label>
</p>
<textarea class="widefat" cols="20" rows="16" id="<?php echo $this->get_field_id('content'); ?>" name="<?php echo $this->get_field_name('content'); ?>"><?php echo $content; ?></textarea>
<?php
}
} // class SuperEmptyWidget
// register SuperEmptyWidget widget
add_action('widgets_init', create_function('', 'return register_widget("SuperEmptyWidget");'));
Just add that to your functions.php and you should have a widget that does not add any crap either before or after the content.