function widget_display_callback( $params ) {
global $wp_registered_widgets;
global $my_widget_num; // Global a counter array
$id = $params[0]['widget_id'];
$sidebar_id = $params[0]['id'];
/* Set some count for each widgets */
if( !$my_widget_num ) { // If the counter array doesn't exist, create it
$my_widget_num = array();
}
if( isset( $my_widget_num[ $sidebar_id ] ) ) { // See if the counter array has an entry for this sidebar
$my_widget_num[ $sidebar_id ] ++;
} else { // If not, create it starting with 1
$my_widget_num[ $sidebar_id ] = 1;
}
$widget_counter = $my_widget_num[ $sidebar_id ];
if( $widget_counter == 1 ) {
$the_class=" widen-full ";
} elseif( $widget_counter == 2 ){
$the_class=" widen-duo ";
} else {
$the_class=" widen-trio ";
}
if ( !empty( $sidebar_id ) && $sidebar_id == 'footer_widgets_area' && !empty( $the_class ) ) {
// add your classes
$classe_to_add = ' ' . $the_class . ' '; // make sure you leave a space at the end
$classe_to_add = 'class=" ' . $classe_to_add;
$params[0]['before_widget'] = str_replace( 'class="', $classe_to_add, $params[0]['before_widget'] );
}
return $params;
}
add_filter( 'dynamic_sidebar_params', 'widget_display_callback', 10 );
Basically you need to use the ‘dynamic_sidebar_params’ hook to add new classes into each widget on the fly. I have implemented the same above to find the widgets count and the index of the widgets inside a sidebar( for your case its: footer_widgets_area ).
Try adding these code on active themes function.php file and check if this works for you !!
You have to replace the sidebar id in this line
if ( !empty( $sidebar_id ) && $sidebar_id == 'footer_widgets_area' && !empty( $the_class ) ) {