History of Sidebars
WordPress has had sidebar functionality, almost from the beginning. This may be because “WordPress started out because the development of an existing blogging software b2/cafelog was discontinued by their main developers.” So, a structure for a basic blog had already been tried, tested, and improved. In 2005, sidebars started being coded as their own element, separate from posts and pages. That opened up the path to the incredibly flexible sidebar functionality we have today.
What is a Sidebar?
The WordPress core functionality makes sidebars possible. Sidebar functionality allows a website owner to manage blocks of content anywhere on their site. The word “sidebar” can be confusing because sidebars don’t have to be along the side of a web page. Sidebars can also be positioned in the header and footer, even in the main area of a post or page. Although sidebars are possible because of the WordPress core, a sidebar is part of a theme. A sidebar is merely a position, a container, that is defined on a page, post or group of pages/posts. .
Content is added into a sidebar with widgets. A sidebar can have multiple widgets. The widgets in a sidebar can be different on different posts or pages. The process of adding a widget to an existing sidebar is separate from the process of creating the sidebar in the first place. Even the WordPress menu item that allows you to add widgets to sidebars says “Widgets” instead of “Sidebars”.
How Is a Sidebar Created?
Most themes come with several sidebars already created. You can see the sidebars that are part of your theme, by going to Dashboard -> Appearance -> Widgets. (Note that “widgets” doesn’t seem like a good place to find the sidebars, but the sidebars do contain the widgets, so that name seems to have stuck.) A sidebar is “created” when it is registered. Registration of a sidebar is a block of code in a theme’s function.php file.
The code looks like this:
‘name’ => __( ‘LeftSidebar’, ”YourTheme’ ),
‘id’ => ‘left-sidebar’,
‘description’ => __( ‘Add widgets here to appear in your left sidebar.’, ‘YourTheme’ ),
‘before_widget’ => ‘<section id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</section>’,
‘before_title’ => ‘<h2 class=”widget-title”>’,
‘after_title’ => ‘</h2>’,
add_action( ‘widgets_init’, ‘YourName_widgets_init’ );
Using the Registered Sidebar
Registering the sidebar does not place the sidebar into a template. Neither does it format the sidebar. Adding items to a sidebar is generally done in the Dashboard -> Appearance -> Widgets. Many plugins come with widgets that can go into a sidebar. For example, a Ninja form can be placed into a sidebar. This site has a plugin called Posts in Sidebar which add the titles of recent posts in certain categories.
When themes already have sidebars, they have done all three steps: 1) registered the sidebar, 2) placed the code in the templates that place the sidebar on a post or page, 3) added formatting to the sidebar. But, you can add as many sidebars as you want in your own custom theme, or in a child theme.