WordPress get_sidebar() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template loader

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.

WordPress
<?php
get_sidebar();
// or a named sidebar:
get_sidebar( 'shop' );
CallWhat 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
WordPress
get_sidebar( string|null $name = null, array $args = [] ): void|false

Parameters

ParameterDescription
$namestring|null. The name of a special sidebar. Default is null.
$argsarray. Extra data for the sidebar file, available as $args. Default is an empty array.

Return Value

Return ValueDescription
void|falseThe 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.

WordPress
<?php get_header(); ?>
<main>Post content</main>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

How It Works

  1. get_sidebar() loads sidebar.php.
  2. That file usually prints the widgets.
  3. The footer comes last.

Example 2 — A sidebar for the shop

Use a different sidebar on shop pages.

WordPress
<?php get_sidebar( 'shop' ); ?>

How It Works

  1. The name is joined to sidebar- and .php.
  2. WordPress tries the named file first.
  3. It falls back to sidebar.php.

Example 3 — Inside sidebar.php

Print the widgets only when there are some.

WordPress
<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
  <aside class="widget-area">
    <?php dynamic_sidebar( 'sidebar-1' ); ?>
  </aside>
<?php endif; ?>

How It Works

  1. is_active_sidebar() checks that the area has widgets.
  2. dynamic_sidebar() prints them.
  3. An empty sidebar prints nothing.

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.

Next: get_template_part()

Load a reusable template file such as content-single.php.

get_template_part() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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