How To get a WordPress Widget ID for Multiple Instances

Supporting Multiple Widget Instances

Just recently I was developing a WordPress widget, and as I began coding of all my use cases I realized that I needed to be able to support multiple widget instances.  Supporting multiple widget instances is not a big deal, unless you plugin depends on knowing the widget id from the front-end.  By this I mean after your page has loaded, you need to perform client-side scripting that depends on knowing the id of each widget instance.

Where is the Widget’s Instance ID stored?

/** @see WP_Widget::widget */
function widget($args, $instance) {
    echo $this->id;
}

Continue reading “How To get a WordPress Widget ID for Multiple Instances”