Untitled UI logotext
Solutions
WebsitesEcommerceMobile AppsWeb AppsProduction Support & Maintenance
Our work
Company
About usBlogPodcastContact us
Book a free consultation

How to Add a Sidebar to a Wordpress Theme

Olivia Rhye

I recently needed a little more control over the sidebar on a theme and had never added a sidebar to a theme before. I wanted certain widgets to show up only on posts and the rest to show up on posts and pages. The below is how to add the sidebar:

In the functions.php page, we need to modify the code which looks like this:

if ( function_exists('register_sidebar') )
register_sidebar();

To make it look like this:

if ( function_exists('register_sidebar') )
{
register_sidebar(array('name'=>'Top Sidebar',));
register_sidebar(array('name'=>'Posts Sidebar',));
register_sidebar(array('name'=>'Bottom Sidebar',));
}

Now, when calling a sidebar, we just need to call it by name as in the following:

//Top Sidebar
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Top Sidebar') ):
endif;
//Posts Sidebar
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Posts Sidebar') ):
endif;
//Bottom Sidebar
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Bottom Sidebar') ):
endif;

Obviously we have freedom to name our sidebars as we please. Look for more info on making a sidebar only show up on posts in an upcoming post.

Ready to start a project?

Book a free consultation
Untitled UI logotext
Our work
About us
Blog
Careers
Submit a ticket
Agency Partnerships
Contact
© 2024 fjorge. All rights reserved.
Privacy