Are you looking to add a new sidebar in your website? A custom sidebar can open many ways in which you can customize the look of your website. A sidebar lets you add various functionalities. You can also add different elements, widgets, display advertisements, show popular posts or add navigational links in the sidebar.
Steps to add a custom sidebar in WordPress without using a plugin
- Navigate to Appearance -> Theme Editor from your admin dashboard.
- Select the Theme Functions(functions.php) file under the Theme Files table.
- Paste the below code in the functions.php file and click on the Update File button.
if ( function_exists('register_sidebar') ) register_sidebar( array( 'name' => __( 'Custom Sidebar'), 'id' =>; 'custom-sidebar', 'description' => __( 'A custom sidebar'), 'before_widget' => '', 'after_widget' => "", 'before_title' => '', 'after_title' => '', ));
4. Now to display the above registered sidebar, add the below code to the sidebar.php file of your theme and click on the Update File button.
dynamic_sidebar( 'Custom Sidebar' );
Note: If your theme doesn’t have a sidebar.php file then you can paste the above code in the Single Post(single.php) file or any part of the website where you want to display the sidebar in. You will have to make some CSS changes to align the sidebar according to your needs. You can change the name Custom Sidebar with your own.
5. Visit Appearance -> Widgets from your admin dashboard. A new option of a Custom Sidebar will now be visible in your widgets section. You can add widgets to it and the changes will be now visible on your WordPress website.
A sidebar can play an important role in increasing the functionalities on your website or helping people navigate your website better. With the help of above code you can add a custom sidebar to your website without using any plugin.