I’m using this code to display widgets of certain sidebar:

$sidebar_id = 'sidebar1';
$sidebars_widgets = wp_get_sidebars_widgets();
$widget_ids = $sidebars_widgets[$sidebar_id]; 
    foreach( $widget_ids as $id ) {
    echo '<li><a href="#'.$id.'">'.$id['title'].'</a></li>';
}

I’m trying to display the widget title using $id['title'], but It’s not working.

2 Answers
2

Found a ‘dirty’ way to do it:

Here’s my code:

$sidebar_id = 'sidebar1';
$sidebars_widgets = wp_get_sidebars_widgets();
$widget_ids = $sidebars_widgets[$sidebar_id]; 
    foreach( $widget_ids as $id ) {
        $wdgtvar="widget_"._get_widget_id_base( $id );
        $idvar = _get_widget_id_base( $id );
        $instance = get_option( $wdgtvar );
        $idbs = str_replace( $idvar.'-', '', $id );
        echo '<li><a href="#'.$id.'">'.$instance[$idbs]['title'].'</a></li>';
    }

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *