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
- Give Editor Access To Sidebar
- Where is the content of widgets stored in mysql table
- Get number of widgets in sidebar
- Show Woocommerce minicart widget in checkout page sidebar? And, how to make this update secure by overriding widget?
- Get sidebar parameters (before_widget, before_title, etc.) from within a widget
- Different widgets on different page templates?
- Widgets not displaying in theme customizer
- Register multiple sidebars
- Determining a Widget Instance and Sidebar Location?
- Randomize widgets displayed in my sidebar [duplicate]
- Remove All Widgets from Sidebar
- Add div class to only one widget
- Unregistering a Sidebar in Child Theme
- Problems with the sidebar args and wp_list_bookmarks
- Ban certain widgets from certain sidebars
- is_active_sidebar() Always Returns False
- Call sidebar from a template
- How could a Widget behave differently depending on sidebar
- Adding classes to dynamic sidebar
- Create variable from widget instance
- display most popular tags in two columns
- Save/update widget outside admin panel [closed]
- Custom widget using get_categories select menu dropdown
- How to insert widget areas specific to certain pages (or posts, etc.)?
- Why use dynamic_sidebar() conditionally?
- WordPress Widget multiple use
- Contact Form in sidebar [closed]
- More flexible sidebar and widget management
- WordPress widget new instance creates content duplicates
- Removing custom widget area WordPress 4.4 [closed]
- How to “pair” two widgets side by side in one sidebar [closed]
- Dynamic Sidebars On Multiple Subpages
- Cannot save widgets in custom sidebars
- Check which registered sidebar a widget is added to
- Disable widgets on specific posts
- WordPress widget/sidebar dividers?
- Missing argument 3 for wp_register_sidebar_widget()
- Excluding specific widgets from default sidebar class
- Can WordPress Read Its Own RSS Feed?
- Can’t see widget areas in my customizer
- Dynamic sidebar based on category
- Widgets not activated alert after using get_sidebar()
- How to show different widgets on different pages in a user friendly way
- How can I get the first section of a page 100% width, while the rest will have a sidebar? [closed]
- Add default widgets to footer
- Trying to create dynamic widget area using post ID
- How to create pagination for homepage with widgetized area?
- Dynamically add content to an existing widget area
- How can I inject html after the [x]th widget inside a Sidebar? [duplicate]
- Programmatically add widgets to sidebars
- Programmatically add widgets to sidebars
- How to determine if the sidebar is empty? Or not active?
- Text Widget in Footer for just 1 page template
- Dynamic Sidebar and XHTML Validity?
- 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
- 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?
- Add class to on sidebar widget
- My website is not showing Footer section
- My widget not printing before_widgets and after widgets
- Check if widget is inside sidebar with PHP
- looping widgets to organize bootstrap grids
- What conditional to use for dynamic sidebar check?
- Stuck with sidebar registering
- Any available action to add content before and after sidebar?
- Why is registering a sidebar for each page causing my sidebars to reset?
- How to Catch Last Widget box From Same Widget Area?
- changing the style of sidebar
- WordPress Local to Live and The Missing Widgets!
- 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
- 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
- How to get sidebar widgets in leftsidebar template
- Add Social Media icon widget to customizer
- Loading scripts only if a particular shortcode or widget is present
- Handling dozens of sidebars
- how to run a php code in widget?
- three sidebars showing without call
- Add sidebar in inner pages
- Inkness theme sidebar
- 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
- Single Widget Multi Sidebar
- How to hide sidebar widgets in all pages except Hompage?
- How to completely remove the sidebar? [closed]
- Subpages menu on sidebar plus widgets
- How to inject a virtual widget (i.e. without adding it to the database) to the sidebar