Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mlbd/8cb2aa2b9c0777fb410706b400c1829a to your computer and use it in GitHub Desktop.
Save mlbd/8cb2aa2b9c0777fb410706b400c1829a to your computer and use it in GitHub Desktop.
function widget( $args, $instance ) {
extract( $args );
... //other code
$widget_width = !empty($instance['widget_width']) ? $instance['widget_width'] : "col300";
/* Add the width from $widget_width to the class from the $before widget */
// no 'class' attribute - add one with the value of width
if( strpos($before_widget, 'class') === false ) {
// include closing tag in replace string
$before_widget = str_replace('>', 'class="'. $widget_width . '">', $before_widget);
}
// there is 'class' attribute - append width value to it
else {
$before_widget = str_replace('class="', 'class="'. $widget_width . ' ', $before_widget);
}
/* Before widget */
echo $before_widget;
... //other code
}
// source - https://wordpress.stackexchange.com/a/19052
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment