Add the following code in your functions.php file of the theme directory. Replace widget name “Home Widget Area” with your widget’s name
/*=============WIDGETs CSS CLASS CONTROLLER==============*/
$GLOBALS['my_widget_num']=1;
function edei_widget_class_adder($params){
if( $params[0]['name']=='Home Widget Area' ){
$GLOBALS['my_widget_num']++;
if( ($GLOBALS['my_widget_num']%4)==0 ){
$params[0]['before_widget'] = str_replace('class="', 'class="marginAdjust ', $params[0]['before_widget']);
}
}
//print_r($params);
return $params;
}
add_filter('dynamic_sidebar_params','edei_widget_class_adder');
function edei_widget_counter_reset($sidebars_widgets) {
$GLOBALS['my_widget_num'] = 1;
return $sidebars_widgets;
}
add_filter('sidebars_widgets','edei_widget_counter_reset');