How to Create a New Custom Sidebar in WordPress

WordPress provides a single sidebar by default. Even more, WordPress provides custom support to fulfil various requirements with a few lines of code. So, we can easily add or remove new sidebars in WordPress for various purposes.

Sidebars are quite helpful and informative for users to easily navigate on a website and to explore helpful content on a website. In blogs, sidebars are used to provide latest, relative and popular articles to readers.

Add a New Sidebar to WordPress

Many themes provide one, two or multiple sidebar according to theme purpose and criteria. But, sometimes we need to create a new sidebar for our custom feature.

It is effortless to create a new sidebar in WordPress. Just follow the below steps to create your own custom sidebar.

Step 1: Go to Theme Editor and Select Theme

First, select the WordPress theme in which you have to add a new sidebar. To do that just go to the Theme Editor from admin panel sidebar and select your desired theme to add a new sidebar.

Step 2: Register a new Sidebar

After that, select functions.php file in the theme files.

Next, copy and paste the below PHP code at the bottom of the file to register a new sidebar and save the functions.php file.

CODE

add_action( 'widgets_init', 'new_sidebar' );
function new_sidebar() {
  $args = array(
    'name'          => 'New Sidebar',
    'id'            => 'new_sidebar',
    'description'   => 'This is a new sidebar.',
    'class'         => '',
    'before_widget' => '<section id="" class="">',
    'after_widget'  => '</section>',
    'before_title'  => '<h2 id="" class="">',
    'after_title'   => '</h2>' 
  );
  register_sidebar( $args );
}

Explanation

In the above code, we created a new sidebar named as new_sidebar with custom parameters and registered it in the WordPress.

Step 3: Add Some Widgets to the New Sidebar

Our sidebar is registered now, to check it just go to the widgets section in your WordPress.

You will notice a new sidebar there named as New Sidebar, add some widgets into it and save the sidebar.

Step 4: Add Sidebar in a PHP Page

Finally, our sidebar is registered with widgets and we are ready to use it in our website.

Go to your desired page in your WordPress theme and paste the below code where you want to display the new sidebar.

<?php dynamic_sidebar( 'new_sidebar' ); ?>

Just clear your website cache in case you are using any plugin for your website optimization and open the webpage where you have added the new sidebar.

I hope you will see your newly created sidebar there with your selected widgets if you have done all the above steps properly.

Read Also: Remove index.php in URL WordPress

Conclusion

WordPress is known for its flexibility to create new features using a little amount of code. Here, we created a new sidebar with some minor changes in functions.php file. I hope you found the above article useful and informative.

Enjoy Customization 🙂

 

Leave a Reply

Your email address will not be published. Required fields are marked *