How to call widget by widget’s id?

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
    }
}

Related posts

Leave a Reply

1 comment

  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
        }
    }