This post is about how to create a WordPress sidebar. At least how I do it. I am using the GeneratePress theme, here, and you’ll have to edit things a bit with a different theme.
Table of Contents
Today, I was called upon again as I was working on a website to register a custom sidebar.
There are easy ways to do this. In the past, I’ve used Content-Aware Sidebars which is a nice way to add widget areas onto any sidebar without any coding at all.
But I don’t really need that, and lately, I’ve been trying to reduce the overall number of plugins I need on my generally plugin-heavy websites.
Most of the time, recently, I’m using the GeneratePress theme, as I like it, support is great, and I’ve grown pretty comfortable with working with it. Note that, whatever you think, I’ve used a LOT of different themes and come to love this one.
But this is about how to create a WordPress sidebar — a custom sidebar, that is.
Note that this is just an example. In this case, I wanted a sidebar just to put a Rate My Post (now FeedbackWP) Top Rated Posts widget inside of and then call it on a specific page where I could then turn it into a grid to display the top-rated posts.
But that’s for another post. This is just the sidebar.
How to create a WordPress sidebar
To register a sidebar, we’re going to use the register_sidebar function in WordPress.
Below is the code I used to register a custom sidebar I called RMP Sidebar. To use this code, you’d want to replace the name RMP Sidebar with whatever you want to call your sidebar, replace “generatepress” with whatever is the actual name of your primary theme, set a slug for your custom sidebar under the “id” section (here, it’s called rmp-sidebar), and change the description to whatever your want.
The code, then, goes into the functions.php file of your child theme.
You should definitely be using a child theme to do this. To set up a child theme, I generally use the Child Theme Configurator plugin as it’s free, has always worked with me, and I can remove it when it’s done configuring the theme. I had a friend who said it messed her website up, but I’m still not sure how it did that, exactly. I’ve never had an issue with it.
The other way you can do this is to use a plugin like code snippets to add it. Many people will advise you to do that. I do not like using code snippets as I find it much easier to just use an FTP client like FileZilla, go to /wp-content/themes/my-child-theme/, open functions.php, edit and save the file, and then just upload that backup (which will prompt you to do automatically). If the code somehow creates an error, I find it very easy to just open the file back up, remove the code, and then diagnose what was wrong — something that I don’t find so easy to do using a plugin like code snippets.
Register sidebar code
/*create the sidebar for rate my post in page*/
add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
register_sidebar( array(
'name' => __( 'RMP Sidebar', 'generatepress' ),
'id' => 'rmp-sidebar',
'description' => __( 'This sidebar is only for the purposes of displaying top rated posts in a page.', 'generatepress' ),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
) );
}
After you do this, you should find your new sidebar in the widgets area in WP-Admin and be able to add widgets to it.
How to add the sidebar to your template
To call the sidebar, then, in my template, I use:
<?php dynamic_sidebar( 'rmp-sidebar' ); ?>
where rmp-sidebar is whatever sidebar ID I set up in the snippet.
In my case, I created a shortcode to insert the above onto a page to show the sidebar, but you can insert it into a template.
Also note that if you insert the register_sidebar code a second time but with a different sidebar name into your functions.php file, it won’t work and you’ll get a critical error. It’s because you’re trying to call the theme_slug_widgets_init twice. I worked around this by changing that, wherever it occurred, to my_theme_slug_widgets_init to create a second custom sidebar.
Anyway, that’s it. I’m adding this before I add a longer post that involves this as a step — that is, how I added a sidebar to the Ultimate Member profile.

Well, I hope that helped you with how to create a WordPress sidebar.
That’s all for now!