$sidebars = array( is_active_sidebar( 'footer-4' ), is_active_sidebar( 'footer-3' ), is_active_sidebar( 'footer-2' ), is_active_sidebar( 'footer-1' ), ); $col = 0; foreach ( $sidebars as $sidebar ) { if ( $sidebar ) { $col++; } } echo 'col-'.$col.'';
What i am trying to accomplish is have the correct number of WordPress active sidebars outputted. So that they can be styled with css example: if 3 sidebars are active you get col-3 if (1) if you col-1.
The code above works. My concern is can it be improved, is this the right way to do it ? Or can increments be used for example: $i = 0; $i++; instead of an array.
Thanks.