
Definition
In WordPress, get_sidebar() loads the theme sidebar file. By default it loads sidebar.php.
If you pass a name, such as get_sidebar( 'shop' ), WordPress looks for sidebar-shop.php first. If it is missing, it falls back to sidebar.php.
Syntax
Call it in a template file, where you want the sidebar to appear.
<?php
get_sidebar();
// or a named sidebar:
get_sidebar( 'shop' );
| Call | What it does |
|---|
get_sidebar() | Loads sidebar.php. |
get_sidebar( 'shop' ) | Loads sidebar-shop.php, then sidebar.php if it is missing. |
get_sidebar( null, $args ) | Loads sidebar.php and passes data to it. |
The widgets themselves are printed with dynamic_sidebar() inside the sidebar file.
Full declaration
get_sidebar( string|null $name = null, array $args = [] ): void|false
Parameters
| Parameter | Description |
|---|
$name | string|null. The name of a special sidebar. Default is null. |
$args | array. Extra data for the sidebar file, available as $args. Default is an empty array. |
Return Value
| Return Value | Description |
|---|
| void|false | The sidebar is loaded. It returns false if no sidebar file was found. |
WordPress Examples
Three short theme examples. Each one shows the code and what it prints.
Example 1 — Add a sidebar to a template
Place the sidebar after the main content.
<?php get_header(); ?>
<main>Post content</main>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
(header.php output)
<main>Post content</main>
<aside class="widget-area">...</aside>
(footer.php output)
How It Works
get_sidebar() loads sidebar.php.- That file usually prints the widgets.
- The footer comes last.
Example 2 — A sidebar for the shop
Use a different sidebar on shop pages.
<?php get_sidebar( 'shop' ); ?>
Loads sidebar-shop.php
If sidebar-shop.php does not exist:
loads sidebar.php
How It Works
- The name is joined to
sidebar- and .php. - WordPress tries the named file first.
- It falls back to
sidebar.php.
Frequently Asked Questions
It loads sidebar.php from your theme, or a named sidebar file if you pass a name.
get_sidebar() loads a template file. dynamic_sidebar() prints the widgets of a registered widget area.
WordPress looks for sidebar-shop.php. If it is missing, it loads sidebar.php.
The widget area may have no widgets, or the ID in dynamic_sidebar() may not match the one you registered.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
10 people found this page helpful