Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to output a unique widget ID inside my mult-instance widgets. So far the following hasn't worked. Is there a unique ID and how do I call it?

Thanks.

function widget($args, $instance) {
// outputs the content of the widget
    extract( $args );
    $widget_id = $instance['widget_id'];    
?>
<?php echo $widget_id ; ?>
<?php
}

Thanks.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

You can get the instance ID with echo $this->id; ($this is the class instance)

The only time you can't get this id is from the form() function, right after you just dropped the widget (here's the reason why)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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