get_sidebar

Load sidebar template.

Description

get_sidebar( (null) $name = null ); 

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

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

Parameters (1)

0. $name — Optional. (null) => null
The name of the specialised sidebar.

Usage

  1. if ( !function_exists( 'get_sidebar' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // The name of the specialised sidebar. 
  5. $name = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_sidebar($name); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/general-template.php  
  1. function get_sidebar( $name = null ) { 
  2. /** 
  3. * Fires before the sidebar template file is loaded. 
  4. * The hook allows a specific sidebar template file to be used in place of the 
  5. * default sidebar template file. If your file is called sidebar-new.php,  
  6. * you would specify the filename in the hook as get_sidebar( 'new' ). 
  7. * @since 2.2.0 
  8. * @since 2.8.0 $name parameter added. 
  9. * @param string|null $name Name of the specific sidebar file to use. null for the default sidebar. 
  10. */ 
  11. do_action( 'get_sidebar', $name ); 
  12.  
  13. $templates = array(); 
  14. $name = (string) $name; 
  15. if ( '' !== $name ) 
  16. $templates[] = "sidebar-{$name}.php"; 
  17.  
  18. $templates[] = 'sidebar.php'; 
  19.  
  20. locate_template( $templates, true );