Use the array_filter() function, which will remove every array element that has false as the value. Then you can count the array length. So your example would look like this:
$sidebars = array(
is_active_sidebar( 'footer-4' ),
is_active_sidebar( 'footer-3' ),
is_active_sidebar( 'footer-2' ),
is_active_sidebar( 'footer-1' ),
);
$active_sidebars = array_filter($sidebars);
echo 'col-'.count($active_sidebars);
Related Posts:
- Show widget differently depending on if it’s in the sidebar or footer
- Multiple rows of footer widget areas
- Can’t edit the widgets sidebar or footer
- How can I inject html after the [x]th widget inside a Sidebar? [duplicate]
- Default widgets assignment – isn’t working
- Copy Widget Settings because of changed IDs
- Programmatically add widgets to sidebars
- Programmatically add widgets to sidebars
- Programmatically add widgets to sidebars
- How to call widget by widget’s id?
- Override WordPress Widget CSS Classes?
- Are widgets meant to be used outside of sidebars?
- wp_get_attachment_image() not displaying post images even though wp_get_attachment_url() echo correct urls
- How to determine if the sidebar is empty? Or not active?
- Text Widget in Footer for just 1 page template
- Show a widget as a sidebar fallback
- Dynamic Sidebar and XHTML Validity?
- Sidebar not appearing in footer, but it appears everywhere else!
- register_sidebar fails when using a include within functions.php
- Update widget form after drag-and-drop “only specific plugin”
- Recent Comments from Specific Category Widget
- Add a specific css to a widget
- Different sidebars not changing
- what is the best way to add things to a side bar
- Is there a simple way to have a new sidebar for each page?
- how to add the same Widget twice to a sidebar?
- Filter Text from sidebar widget?
- Different widgets in sidebar on sub-children pages?
- Display posts from category in post content?
- Add class to on sidebar widget
- My website is not showing Footer section
- Cannot change footer text?
- My widget not printing before_widgets and after widgets
- Is there a way to use get_sidebar() when no widgets are activated?
- Add footer widgets
- Check if widget is inside sidebar with PHP
- New Widget are not showing
- looping widgets to organize bootstrap grids
- What conditional to use for dynamic sidebar check?
- Add a select-option to the default widgets
- How do I exclude portrait pictures from the nextgen gallery sidebar widget?
- Stuck with sidebar registering
- Any available action to add content before and after sidebar?
- Distinguish between different widgets of the same type
- Don’t display a sidebar widget when on a specific page
- links to Media Library content in sidebar per page
- Upgraded to 3.3, My Widgets Disappeared
- Why is registering a sidebar for each page causing my sidebars to reset?
- How to Catch Last Widget box From Same Widget Area?
- activate custom sidebar widgets
- changing the style of sidebar
- How can I detemine the parameters needed by the_widget()?
- widgets in footer?
- WordPress Local to Live and The Missing Widgets!
- Retrieve the whole widget sidebar and pass it inside an html
- Loading Widgets Via Child Theme
- Need to delete the sidebar widget area and have the page a full page rather than just have a blank widget area
- How can I have sidebar widgets on Twenty Seventeen theme on all pages?
- why the code html apear in this widget in footer
- My theme didn’t appear sidebar area
- Before_widget won’t show up
- How to create sidebar from “scratch”?
- Display current tag archive’s name and description in sidebar
- How do I add footer widgets to the StudioPress Monochrome Pro theme?
- Need two sidebar (right and left)in Twenty Seven theme
- Reposition the widget sidebar in Appearance->Widgets
- Sidebar widgets are over the content in mobile mode, how can I fix it? [closed]
- How to get sidebar widgets in leftsidebar template
- How can the searchform.php know if it’s used on a registered sidebar id ‘sidebar-1’ or ‘sidebar-2’?
- How to list categories by page id in wordpress
- Recent Posts Widget URL / Domain change
- Add Social Media icon widget to customizer
- Loading scripts only if a particular shortcode or widget is present
- Handling dozens of sidebars
- Use customizer or sidebar for header settings?
- Script in sidebar blocks other widget’s load
- Make a widget to my footer
- Does current page contain widget or sidebar
- widgets_init actions not fired from functions.php’s child theme
- how to run a php code in widget?
- three sidebars showing without call
- Active Sidebar Conditional Question?
- Cannot access variables within a widget
- Target logic based on Widget / Sidebar Name
- Can I get variable into dynamic sidebar?
- Paginate recent posts widget
- Add sidebar in inner pages
- $before/after_widget/title not displaying anything
- if is within sidebar [duplicate]
- Inkness theme sidebar
- how to call new widgets in sidebar in custom theme?
- Template from scratch: Sidebars not showing widget
- How can I get the sidebar id on the current page?
- My custom widget won’t stay in the widget area after I refresh the widget page
- Automatically hide Widgets that would lengthen page
- user definable sidebar per page
- Call sidebar from a template
- Show or hide custom menu widget in side bar conditionally
- Custom tabs widget don’t work in google chrome, is blocked, do not change the tabs. Why?
- Single Widget Multi Sidebar