Sidebars can be a confusing term in WordPress. This is mostly because in the context of themes and web design, the sidebar is a component of a website’s layout. But in WordPress, sidebar can also refer to dynamic sidebars, or widgetized areas. These are blocks of space where you can drag and drop widgets in the WordPress admin, then output them to your theme, anywhere. To add to the confusion, dynamic sidebars do not necessarily have to output their content to the sidebar in your layout, they can actually be included in any template file.
In this post, I’ll briefly touch on what sidebars are in the context of a theme’s layout, then move on how to use dynamic sidebars and widgets to get the most out of your theme.
In WordPress, theme’s are made up of different components, that are rendered when a user accesses your site. This includes the header and footer, the main content of your page, and the sidebar that is often displayed on the left or right of a theme. Each of these components get its own template file, a chunk of PHP that uses WordPress tags to output content you’ve added in the admin
One of these templates is the sidebar template. In its simplest form, this file will be called “sidebar.php.” Any kind of content can be added to this template file, but typically this is used to store the contents of your widgetized areas, which we’ll talk about in a bit. To add this template file to your theme, you have to use theget_sidebar function. If you named your file “sidebar.php” then you simply have to open up a template file, scroll to where you want to add your sidebar and add:
It’s also possible to set up multiple sidebar templates for inclusion in your theme, so that different pages get different sidebars. For instance, you may want to have one for posts, and another for pages. To create multiple sidebars, you have to add a suffix to the template’s PHP file. For instance, we can call one template “sidebar-left.php.” Then, we can use the get_sidebar function again to retrieve this template, this time adding a name to the function.
We added “left” here to tell WordPress that we want the file called “sidebar-left.php,” not the default template. Sidebars are useful for any resuable bits of content. The header and footer will cover the top and bottom of your page, but sidebar templates can be used to add blocks of content shown on every page, extra navigation, or a search bar. Most themes come with one or several sidebar templates included, and they often include default data to get you started. Of course, to get full use of the sidebar template, you will probably want to add a dynamic sidebar to it.
Dyanmic sidebars, also known as widgetized areas, are empty spaces you can add widgets to in the WordPress admin. Typically, these are included in the sidebar templates we touched on above, but they can be added to any part of your content, above or below a post for instance with for more click here now .Most themes come bundled with a few widgetized areas that you can start adding content to right away. To see your own themes, you can go to Appearance -> Widgets in the WordPress admin.
On the right side of the page you will see a list of widget areas that are available in your theme. You can drag and drop widgets into any of these areas, and they will start showing up on your site. There are lots of widgets to choose from out of the box, like a list of recent posts or comments, and plenty of widgets available as plugins.
This may be enough for you, but it’s also possible to add your own custom widgetized area for use somewhere else in your theme. There are two steps for setting up a dynamic sidebar:
- Register your widgetized area
- Output the widget block in your theme
In this example, we will be creating a new widgetized area that will be displayed at the bottom of post pages. This will contain information about the site and the author, which will be added as widgets to our dynamic area. I’ll be using a child theme of Divi, but this should work for any theme out there.
Registering a Widgetized Area in Elegant Themes
If you are using a theme from Elegant Themes, then you will be able to register a new sidebar in the WordPress admin without needing any code. To do so, go toAppearance -> Widgets in the WordPress admin. You will see a list of widgetized areas already set up for you on the right side of the page. This will include the layout’s sidebar, as well as a few footer areas you can include in your theme.[wysija_form id=”1″]