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.
Index
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.
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.
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.
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.
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
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 🙂
There is a reason big-name companies like CNN use WordPress. WordPress is a popular content…
In this tutorial, I'm going to show you how to install MySQL on your computer.…
Download Turbo C++ for windows 10 in just 7 Mb and run your first C++…
We can redirect any webpage to any other or redirect the whole domain or website…
There are lots of methods to redirect pages, like refresh-redirect from META tag, redirect from…
Include files in PHP are used in appending various global or config files. We can…