Get sidebar parameters (before_widget, before_title, etc.) from within a widget

The parameters are given (as an array) as the first argument provided to the widget method. The second argument, $instance, holds the options for that particular instance of the widget.

My usual set up is:

 function widget($args, $instance){
    //Extract the widget-sidebar parameters from array
    extract($args, EXTR_SKIP);

    echo $before_widget;
    echo $before_title;
    //Display title as stored in this instance of the widget
    echo esc_html($instance['title']); 
    echo $after_title;
    //Widget content
    echo $after_widget;

 }

Leave a Comment