0

Pretty often I use one widget area placed in the footer of my theme, what displays its widgets as columns. As a theme developer I try to offer as much flexibility as possible. So if the theme user wants a specific amount of columns in the footer, than 1, 2, 3 or 4.. columns. It shouldn't be any problem, they all will fit perfectly (as long as css supports it).

Unfortunately I couldn't find a way to render my widgets in a similair way as posts are rendered. I want an array of widgets of a specific area, so I can count them and calculate what column class should be used on the container element of the widget.

6
  • Yes, there's a great plugin for this. That guy scraped the code from few developers and designed this -> wordpress.org/plugins/limit-widgets
    – Josip Ivic
    Commented Aug 17, 2016 at 15:26
  • @JosipIvic Thanks the answer probably can be found in that plugin's source. Unfortunately it's not exactly what I'm looking for, because this plugin sets a limit for the amount of widgets on all widget areas.
    – luukvhoudt
    Commented Aug 17, 2016 at 15:32
  • Can you provide some context as to why you would need to do this?
    – Tom J Nowell
    Commented Aug 17, 2016 at 15:36
  • @JosipIvic if that answers the question can you write an answer and be sure to write up how that plugin does what it does?
    – Tom J Nowell
    Commented Aug 17, 2016 at 15:37
  • 1
    Possible duplicate: wordpress.stackexchange.com/q/19907/11761
    – Max Yudin
    Commented Aug 17, 2016 at 15:47

1 Answer 1

1

How do I get an array of widgets?

You can look into

$sidebars_widgets =  wp_get_sidebars_widgets();
print_r( $sidebars_widgets );

Here's an output example:

Array
(
    [orphaned_widgets_1] => Array
        (
            [0] => text-6
        )

    [wp_inactive_widgets] => Array
        (
            [0] => text-7
            [1] => rss-2
        )

    [sidebar-1] => Array
        (
            [0] => recent-posts-3
            [1] => recent-posts-4
            [2] => text-9
            [3] => calendar-2
            [4] => categories-3
            [5] => search-4
            [6] => text-8
            [7] => categories-2
        )

    [sidebar-2] => Array
        (
            [0] => search-5
        )

    [sidebar-3] => Array
        (
            [0] => recent-posts-2
        )

)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.