Are you looking for a way to register several widget areas in WordPress? While there’s probably a plugin for this, we have created a quick code snippet that you can use to register several widget areas in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
// In functions.php register_sidebar(array( 'name' => 'Sidebar', 'id' => 'sidebar', 'before_widget' => '<li>', 'after_widget' => '</li>', 'before_title' => '<h3>', 'after_title' => '</h3>' )); register_sidebar(array( 'name' => 'Footer', 'id' => 'footer', 'before_widget' => '<li>', 'after_widget' => '</li>', 'before_title' => '<h3>', 'after_title' => '</h3>' )); // In sidebar.php if ( is_sidebar_active('sidebar') ) { dynamic_sidebar('sidebar'); } // In footer.php if ( is_sidebar_active('footer') ) { dynamic_sidebar('footer'); }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 11 best WordPress plugins for writers and how to create a guest post submission form in WordPress.
Comments Leave a Reply