Created
February 14, 2018 08:14
-
-
Save mlbd/8cb2aa2b9c0777fb410706b400c1829a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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