How to Create a New Custom Sidebar in WordPress

WordPress provides a single sidebar by default. Even more, WordPress provides custom support to fulfill 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 a website and explore helpful content on a website. In blogs, sidebars are used to provide the latest, relative, and popular articles to readers.

Add a New Sidebar to WordPress

Many themes provide one, two, or multiple sidebars 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, just go to the Theme Editor from the admin panel sidebar and select your desired theme to add a new sidebar.

Step 2: Register a new Sidebar

After that, select the 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

We created a new sidebar named new_sidebar with custom parameters in the above code and registered it in WordPress.

Step 3: Add Some Widgets to the New Sidebar

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

You will notice a new sidebar named 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 on our website.

Go to your desired page in your WordPress theme and paste the below code 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 small amount of code. Here, we created a new sidebar with some minor changes in the 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 *

Read previous post:
cookies in php
Cookies in PHP

Like all other web languages, PHP also provides Cookies to store some data for a long time on the client-side....

Close