Over the years developing WordPress themes, I have worked with many designs that require page specific widgets or sidebars. While it has been possible to accomplish this using a combination of PHP if/else statements, Widget Logic, Widget Context, or other plugins, I have yet to find a decent solution for managing sidebars for specific pages. Since many of the sites I now work on require this functionality, I decided it was time to write a rather simple but effective plugin that handles this. Therefore, I’m introducing Unique Page Sidebars.
There are obviously some limitations to this plugin, and I don’t expect to use it on every site I develop, but I chose the most common use-case I have for needing per page sidebars, and developed this plugin to fit that need. That said, here is a list of features:
- Creating an unlimited number of sidebars, each with customizable names, descriptions and before/after title/widget tags (see options of register_sidebar() on the WordPress codex)
- Mapping any of the created sidebars to anywhere from 1 to unlimited number of pages
- Only one line of code needed in your theme
- Can easily default to a default sidebar
However, there are a few drawbacks (some of which I’m looking to working out in subsequent versions):
- Only one sidebar per-page
- No ‘default’ options for new sidebars
- Can’t display sidebars on specific archives, posts, etc.
To install, download the .zip, unpack it and upload to your WordPress installation in /wp-content/plugins/. Log in to the admin backend and activate it on the Plugins page. You should now see another menu item under “Appearance” called “Manage Sidebars” which will be where you can manage all of the sidebars.
In your theme, all you need to add is the following line where you would like the dynamic sidebar to show up:
<?php dynamic_sidebar( apply_filters( 'ups_sidebar', 'default-sidebar-id' ) ); ?>
In the above snippet of code, ‘default-sidebar-id’ is simply the ID for your default sidebar which you should define in your functions.php file using
For example, in your theme you should see a line of code that contains:
<?php dynamic_sidebar( 'primary' ); ?>
You would change that to:
<?php dynamic_sidebar( apply_filters( 'ups_sidebar', 'primary' ) ); ?>
Here are a couple screenshots of the sidebar management screen:
Current version: 0.2 (August 28, 2012)
- Fixed bug where the first sidebar would create with an ID of 2 and subsequent sidebars fail to save.
- Add ryno_sidebar filter since I had my docs wrong (moved from ryno_ to ups_ during initial development).
- Initial version