im building wordpress theme and i created 4 sidebars to use on footer, now i need to have dynamic width of those 4 sidebars depending of how many of them are active.
So for example if i have only footer1 sidebar active, his width should be 100%
If i have footer1 and footer2, or footer1 and footer4, or footer2 and footer3 active they should be 50%,
If i have 3 of them active 33%
And if i have all 4 of them each one should be 25% width.
Just to say again, these are not active widgets in one sidebar, all 4 of them are separated sidebars.
I think this could be done with “switch” and “case” php functions, or with “if” but i don’t know how to count them.
It looks like you could use
wp_get_sidebars_widgets
, which returns an associative array of sidebars and their widgets.With that in mind you could do something like this to set the width of the sidebar. You will need to create the CSS classes to match the names I’ve chosen to specify the width.