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.
Works based on: locate_template()
Hooks from the function
Return
null/false. Void on success, false if the template does not exist.
Usage
get_sidebar( $name, $args );
- $name(string)
- The name of the specialised sidebar.
Default: null - $args(array)
- Additional arguments passed to the sidebar template.
Default: empty array
Examples
#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() theme_sidebar();
Changelog
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() get sidebar WP 5.6
Related Functions
From category: Theme files connection
- comments_template()
- get_footer()
- get_header()
- get_parent_theme_file_path()
- get_parent_theme_file_uri()
- get_search_form()
More from Template Tags: Main Functions
- bloginfo()
- calendar_week_mod()
- get_bloginfo()
- get_calendar()
- get_current_blog_id()
- is_404()
- is_active_sidebar()
- is_admin()
- is_archive()
- is_attachment()
- is_author()
- is_category()
- is_comment_feed()
- is_date()
- is_day()
- is_dynamic_sidebar()
- is_embed()