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.

Is it possible to call widgets using it's id? for example I have a sidebar. In this sidebar I put meta widget and tag cloud widget. I have got their id's ($widgets_list): 'meta-2' and 'tag_cloud-2'. How can I call them without dinamic_sidebar function.

foreach($widgets_list as $item){
    if($item =='meta-2'){
        //echo widget with 'meta-2' id here
    }
}
share|improve this question

1 Answer 1

You can display the specified widget using the_widget. It takes the class name of the widget as an argument (not ID), so you'll need to know that info to use it, but this allows you to use a widget outside the sidebar.

If you're looking to run some code based on the presence of a plugin, you want to use is_active_widget, which does take the ID as a parameter.

foreach( $widgets_list as $item ) {
    if ( is_active_widget( false, false, $item, true ) ) {
        //do your thing
    }
}
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.