Call sidebar from a template

Impossible with get_sidebar().

From that function’s body:

function get_sidebar( $name = null ) {
    do_action( 'get_sidebar', $name );

    $templates = array();
    if ( isset($name) )
        $templates[] = "sidebar-{$name}.php";

    $templates[] = 'sidebar.php';

So if you pass a $name or any other custom value to the function, they will be set between two fixed strings.

You can use locate_template() instead:

locate_template( 'pgwidgets/sidebar-homepage.php', TRUE );

Leave a Comment