I would not recommend that. Much easier to use a clearfix hack to force clearing and just add that style to your widget. Clearfix hacks are transparent: it doesn’t matter if they happen on all elements there is no visible difference, other than clear floats.
Somewhere in your themes style.css
:
.widget:before,
.widget:after {
content: " ";
display: table;
}
.widget:after {
clear: both;
}
.widget {
*zoom: 1;
}
You can, of course, put that anywhere. You could hook into wp_head
or wp_footer
and spit out a custom style tag just for that. Or you could be more specific. For instance if you’re registering a custom widget, you could add a clearfix hack to that specifically by classname.
Alternatively, if you really want to just add a clear div to a certain widget, you can hook into dynamic_sidebar_params
. Your hooked function will receive a single argument: an array of sidebar params — including before_widget
and after_widget
and widget_name
which will be the second argument you passed to parent::__construct
when you register the widget. Something like this:
<?php
add_filter('dynamic_sidebar_params', 'wpse90953_sidebar_params');
function wpse90953_sidebar_params($widget_params)
{
if (!empty($widget_params['widget_name']) && 'your_widget_name' === $widget_params['widget_name']) {
$widget_params['before_widget'] = '<div style="clear:both"></div>' . $widget_params['before_widget'];
}
return $widget_params;
}