Add class to before_widget from within a custom widget

Posted by Prem Tiwari | Updated on

Aha, so the $before_widget variable is a string representing div element: <div class="widget my" id="my-widget-1"> . So I checked the $before_widget for the “class” sub-string and added my $widget_width value to it.

The code is from my custom widget file:

I wanted to add my $widget_width variable to the widget div element within my own widget code (while I had an easy access to the $widget_width variable).

Hope that makes sense and will help someone.

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers