Title: get_sidebar
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_sidebar( string|null $name = null, array $args = array() ): void|false

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#wp--skip-link--target)

Loads sidebar template.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#description)󠁿

Includes the sidebar template for a theme or if a name is specified then a specialized
sidebar will be included.

For the parameter, if the file is called “sidebar-special.php” then specify “special”.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#parameters)󠁿

 `$name`string|nulloptional

The name of the specialized sidebar.

Default:`null`

`$args`arrayoptional

Additional arguments passed to the sidebar template.

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#return)󠁿

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

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#source)󠁿

    ```php
    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;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/general-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/general-template.php#L115)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/general-template.php#L115-L139)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#hooks)󠁿

 [do_action( ‘get_sidebar’, string|null $name, array $args )](https://developer.wordpress.org/reference/hooks/get_sidebar/)

Fires before the sidebar template file is loaded.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#related)󠁿

| Uses | Description | 
| [locate_template()](https://developer.wordpress.org/reference/functions/locate_template/)`wp-includes/template.php` |

Retrieves the name of the highest priority template file that exists.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | The `$args` parameter was added. | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 7 content](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#comment-content-474)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_sidebar/#comment-474)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-474)
     Vote results for this note: 15[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-474)
 4.  **Simple call**
      Assume you have file `wp-content/yourTheme/sidebar-nice-bar.php`.
     The way you can include this sidebar in your page is:
 5.      ```php
         <?php get_sidebar('nice-bar'); ?>
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%3Freplytocom%3D474%23feedback-editor-474)
 7.   [Skip to note 8 content](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#comment-content-476)
 8.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_sidebar/#comment-476)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-476)
     Vote results for this note: 6[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-476)
 10. **Left and Right Sidebars**
      Two sidebars in one theme.
 11.     ```php
         <?php get_header(); ?>
         <?php get_sidebar( 'left' ); ?>
         <?php get_sidebar( 'right' ); ?>
         <?php get_footer(); ?>
         ```
     
 12. The file names for the right and left sidebars should be `sidebar-right.php`` 
     and ``sidebar-left.php` respectively.
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%3Freplytocom%3D476%23feedback-editor-476)
 14.  [Skip to note 9 content](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#comment-content-477)
 15.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_sidebar/#comment-477)
 16. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-477)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-477)
 17. **Multi sidebars**
      Different sidebar for different pages.
 18.     ```php
         <?php
         if ( is_home() ) :
           get_sidebar( 'home' );
         elseif ( is_404() ) :
           get_sidebar( '404' );
         else :
           get_sidebar();
         endif;
         ?>
         ```
     
 19. The file names for the home and 404 sidebars should be `sidebar-home.php` and `
     sidebar-404.php` respectively.
 20.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%3Freplytocom%3D477%23feedback-editor-477)
 21.  [Skip to note 10 content](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#comment-content-475)
 22.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_sidebar/#comment-475)
 23. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-475)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-475)
 24. **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).
 25.     ```php
         <?php get_header(); ?>
         <h2>Error 404 - Not Found</h2>
         <?php get_sidebar(); ?>
         <?php get_footer(); ?>
         ```
     
 26.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%3Freplytocom%3D475%23feedback-editor-475)
 27.  [Skip to note 11 content](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#comment-content-4567)
 28.   [Thirumani Guhan](https://profiles.wordpress.org/thirumani02/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/get_sidebar/#comment-4567)
 29. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-4567)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-4567)
 30. **Call sidebar with $args parameter (Since 5.5.0)**
      Consider below is your sidebar
     call from anywhere inside your theme,
 31.     ```php
         <?php 
         $args = array(
         	'title' => 'Shop sidebar'
         );
     
         get_sidebar( 'shop', $args ); 
     
         ?>
         ```
     
 32. Your codes inside `sidebar-shop.php` file might look a like below.
 33.     ```php
         <div id="secondary" class="widget-area sidebar-shop" role="complementary">
         	<h2><?php echo esc_html( $args['title'] ); ?><h2>
         	<?php dynamic_sidebar( 'sidebar-shop' ); ?>
         </div><!-- #secondary -->
         ```
     
 34.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%3Freplytocom%3D4567%23feedback-editor-4567)
 35.  [Skip to note 12 content](https://developer.wordpress.org/reference/functions/get_sidebar/?output_format=md#comment-content-3136)
 36.   [tradesouthwest](https://profiles.wordpress.org/tradesouthwestgmailcom/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/get_sidebar/#comment-3136)
 37. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-3136)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%23comment-3136)
 38. **Conditional Statement for Any Sidebar**
      In case you are making a plugin template
     where you do not know if there is a sidebar, for any given theme the plugin may
     be used with, you may check for `register_sidebar` function to see if any sidebar
     exists.
 39.     ```php
         if ( function_exists( 'register_sidebar' ) ) { 
         	get_sidebar(); 
         } 
         ```
     
 40. Or, if you know the theme registered name for the sidebar in question try:
 41.     ```php
         //for twenty-sixteen theme
             if ( is_active_sidebar( 'content-bottom' ) ) : 
                 get_sidebar( 'content-bottom' ); 
             endif; 
         ```
     
 42.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F%3Freplytocom%3D3136%23feedback-editor-3136)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_sidebar%2F)
before being able to contribute a note or feedback.