WordPress at Your Fingertips

get_sidebar() WP 1.5.0

Includes the sidebar.php template file from your current theme's directory. If a $name is specified then sidebar-{name}.php will be included.

If the theme contains no sidebar.php file then the sidebar from the default theme wp-includes/theme-compat/sidebar.php will be included.

Hooks from the function


null|false. Void on success, false if the template does not exist.


get_sidebar( $name, $args );
The name of the specialised sidebar.
Default: null
Additional arguments passed to the sidebar template.
Default: empty array


#1 Using two sidebars in the theme

<?php get_header(); ?>
<?php get_sidebar('left'); ?>
<?php get_sidebar('right'); ?>
<?php get_footer(); ?>

#2 Including a sidebar from theme's subdirectory

// Includes 'inc/sidebar.php' file from the current theme's directory. 
// Put this code into functions.php
function theme_sidebar( $name = '' ){
	do_action( 'get_sidebar', $name );

	if( $name )
		$name = "-$name";

	locate_template("inc/sidebar$name.php", true);

// call instead of get_sidebar()


Since 1.5.0 Introduced.
Since 5.5.0 A return value was added.
Since 5.5.0 The $args parameter was added.

Code of get_sidebar() WP 5.8.1

function get_sidebar( $name = null, $args = array() ) {
	 * Fires before the sidebar template file is loaded.
	 * @since 2.2.0
	 * @since 2.8.0 The `$name` parameter was added.
	 * @since 5.5.0 The `$args` parameter was added.
	 * @param string|null $name Name of the specific sidebar file to use. Null for the default sidebar.
	 * @param array       $args Additional arguments passed to the sidebar template.
	do_action( 'get_sidebar', $name, $args );

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

	$templates[] = 'sidebar.php';

	if ( ! locate_template( $templates, true, true, $args ) ) {
		return false;

Theme files connection

Main Functions

No comments
    Log In