How to determine the current widget’s parent container (sidebar widget id)

I have several custom widgets that are installed as part of my theme. I’d like to execute conditional code inside each widget’s admin panel (not the public side, I’m just interested in the admin panel inside function form($intance)), depending on which sidebar the widget is inserted into.

How can I obtain a reference to the current sidebar id which holds the widget, from within the widget’s function form($instance) handler?

3 Answers
3

If your widgets use the widget API you should have the following method in your widget class…

function widget($args, $instance){
    //output html here...
}

$args['id'] will hold the id of the current sidebar.

Leave a Comment