I created a widget by extending WP_Widget, works well. Also added a field to the admin called className.
But I can’t find any hook where I can inject the custom CSS class name into the rendering code of the widget (I want the class to be applied to the whole widget of course).
// Before widget.
echo $before_widget;
if ($title)
{ echo $before_title.$title.$after_title; }
if ($headline)
{ echo '<h4>'.$headline.'</h4>'; }
if ($description)
{ echo '<p>'.$description.'</p>'; }
if ($className)
{ echo '<p>Class name: '.$className.'</p>'; }
// After widget.
echo $after_widget;
The HTML output for this goes like:
<aside id="eppz-page-widget-2" class="widget widget_eppz-page-widget">
<h3 class="widget-title">Title</h3>
<h4>Headline!</h4>
<p>Some description that can be added optionally to the widget.</p>
<p>Class name: featuredPageWidget</p>
</aside>
Now I really want to append the className variable after all the classes applied to aside. I could do it with some string functions, but I’d really hope that there is a simple WordPressy way to do this.