WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/get sidebar

Contents

Description

Includes the sidebar.php template file from your current theme's directory.

If a name ($name) is specified then a specialized sidebar sidebar-{name}.php will be included. If sidebar-{name}.php does not exist, then it will fallback to loading sidebar.php.

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

Usage

<?php get_sidebar$name ); ?>

Parameters

$name
(string) (optional) Calls for sidebar-name.php.
Default: None

Examples

Simple 404 page

The following code is a simple example of a template for an "HTTP 404: Not Found" error (which you could include in your Theme as 404.php).

<?php get_header(); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Left and Right Sidebars

Two sidebars in one theme.

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

The file names for the right and left sidebars should be sidebar-right.php and sidebar-left.php respectively.

Multi sidebars

Different sidebar for different pages.

<?php
if ( is_home() ) :
	get_sidebar( 'home' );
elseif ( is_404() ) :
	get_sidebar( '404' );
else :
	get_sidebar();
endif;
?>

The file names for the home and 404 sidebars should be sidebar-home.php and sidebar-404.php respectively.

Notes

Change Log

  • Since: 1.5.0
  • 2.5.0 : Added the 'name' parameters.

Source File

get_sidebar() is located in wp-includes/general-template.php.

Related

Include Tags

Widgets: is_active_widget(), the_widget(), register_widget(), unregister_widget(), wp_register_widget_control(), wp_unregister_widget_control(), wp_convert_widget_settings(), wp_get_widget_defaults(), wp_widget_description()

See also index of Function Reference and index of Template Tags.