Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get sidebar


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.


<?php get_sidebar$name ); ?>


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


Simple call

Assume you have file wp-content/yourTheme/sidebar-nice-bar.php. The way you can include this sidebar in your page is:

<?php get_sidebar('nice-bar'); ?>

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.

if ( is_home() ) :
  get_sidebar( 'home' );
elseif ( is_404() ) :
  get_sidebar( '404' );
else :

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


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.


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.