Creating Custom Sidebars in WordPress Themes

Posted on 19th June 2023

Creating Custom Sidebars in WordPress Themes

WordPress themes are very flexible and customizable. One of the features you can customize is the sidebar. Sidebars can be changed per page or post, or you can create a custom sidebar and display it on certain pages or posts.

In this article, we will show you how to create custom sidebars in WordPress themes.

What is a Sidebar in WordPress?

A sidebar in WordPress is a widget-ready area that is usually displayed on the right or left side of the web page. It is called a sidebar because it is usually used to display information that is not a part of the main content.

This might include the author’s bio, social media buttons, advertisements, recent posts, or popular posts.

Most WordPress themes come with multiple sidebars. For example, the twenty seventeen theme has a total of four sidebars.

How to Create a Custom Sidebar in WordPress?

Creating a custom sidebar in WordPress is easy. First, you need to install and activate the Custom Sidebars plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Appearance » Widgets page. Here you will find the newly created ‘Custom Sidebars’ section.

You can now start creating custom sidebars. Give your sidebar a name and click on the ‘Add Widget’ button to add widgets to your sidebar.

Once you are done, click on the ‘Save Changes’ button to store your settings.

You can now preview your website to see the custom sidebar in action.

How to Display Custom Sidebars in WordPress?

Now that you have created a custom sidebar, it is time to display it on your website. The Custom Sidebars plugin comes with a few options to do that.

The simplest way is to choose a sidebar from the ‘Custom Sidebars’ dropdown and click on the ‘Add Sidebar’ button.

This will add the sidebar to the list of registered sidebars for your theme. Now you can go to Appearance » Widgets page and start adding widgets to your custom sidebar.

Another way to display custom sidebars is by using the ‘Display Sidebar’ widget. This widget is available under the ‘Custom Sidebars’ section.

Simply add the ‘Display Sidebar’ widget to a sidebar, and then choose the sidebar you want to display from the dropdown.

You can also use the ‘Display Sidebar’ widget to display a custom sidebar on specific posts and pages.

Simply check the ‘Display on specific post types’ checkbox and then choose the post type where you want to display the sidebar.

If you want to display the sidebar on specific posts or pages, then you need to enter the post or page IDs in the ‘Display on specific posts/pages’ text field.

You can find the post or page ID by hovering over the title of the post or page in the WordPress admin area. The ID will be displayed in the browser’s status bar.

Once you are done, click on the ‘Save Changes’ button to store your settings.

You can now visit your website to see the custom sidebar in action.

How to Manage Sidebars in WordPress Themes?

As we mentioned earlier, most WordPress themes come with multiple sidebars. You can change what sidebar appears on which part of your website from the theme settings page.

For example, the twenty seventeen theme allows you to choose different sidebars for your front page, blog page, and single post pages.

Similarly, many themes also come with a sidebar manager that allows you to create custom sidebars and assign them to specific pages or posts.

We hope this article helped you learn how to create custom sidebars in WordPress. You may also want to see our list of the most essential WordPress plugins for business websites.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

In order to create a sidebar in a WordPress theme, you need to register it with WordPress. To do this, you need to add some code to your theme’s functions.php file. The code you need to add is as follows:

__( ‘Main Sidebar’, ‘my-theme’ ),

‘id’ => ‘main-sidebar’,

‘before_widget’ => ‘

‘,

‘after_widget’ => ‘

‘,

‘before_title’ => ‘

‘,

‘after_title’ => ‘

‘,

)

);

}

add_action( ‘widgets_init’, ‘my_sidebar_init’ );

?>

This code registers a sidebar with WordPress and gives it a name (Main Sidebar) and an id (main-sidebar). It also sets up some HTML which will be output before and after each widget in the sidebar, and before and after the sidebar’s title.

Once you have registered a sidebar, you can then add widgets to it from the WordPress admin interface. To do this, go to Appearance > Widgets and drag the widgets you want to appear in your sidebar into the sidebar area.

If you want to output your sidebar in your theme, you can use the WordPress function dynamic_sidebar(). This function takes the id of the sidebar as its parameter. So, in our example, we would use the following code:

This code would output the sidebar with the id of main-sidebar.

If you want to create multiple sidebars, you can register multiple sidebars with WordPress by adding more sidebar registration code to your theme’s functions.php file. Each sidebar you register will then appear as a separate widget area in the WordPress admin interface, and you can output each one in your theme using dynamic_sidebar().

In most themes, the sidebar is displayed on the right side of the page. If you want to change that, you can do so in the Customizer.

In the Customizer, go to Appearance > Widgets. Then, click on the sidebar you want to change. In the Sidebar Settings section, select the new location for the sidebar from the Sidebar Location dropdown.

You can also change the width of the sidebar in the Customizer. In the Sidebar Width section, enter the new width in pixels.

If you want to change the sidebar on a specific page or post, you can do so in the Page Attributes meta box. In the Template dropdown, select the custom sidebar template.

You can also create a custom sidebar for a specific page or post. To do this, go to Appearance > Widgets and click on the Add a Widget button. In the Widget Type dropdown, select Custom HTML. Then, enter the HTML for the sidebar in the Content text area.

If you want to display a different sidebar on your home page, you can do so in the Customizer. Go to Appearance > Widgets and click on the Home Page Sidebar widget area. Then, select the sidebar you want to display from the Sidebar dropdown.