Unique Page Sidebars

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.

Installation

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 register_sidebar().

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' ) ); ?>

Screenshots

Here are a couple screenshots of the sidebar management screen:

Download

Download a copy on WordPress.org!

Current version: 0.2 (August 28, 2012)

Changelog

Version 0.2

  • 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).

Version 0.1

  • Initial version

12 thoughts on “Unique Page Sidebars

  1. Eamon

    Hi, Fantastic plugin, just what I need, unfortunately I am not a PHP developer but I know HTML and CSS pretty well, I need a dummy’s guide to making this plugin work.
    I have installed it no problem, but the functions.php and register sidebar business has me a bit confused, sorry for being a dummy!!!! but I’d appreciate a dummys guide to making this work. Thanks and again excellent plugin. regards Eamon

    Reply
  2. Carsten

    Somehow I can only create one additional sidebar and I can’t even get this sidebar to show on the associated page. I even removed all other sidebars (was 4 side and 3 footer), but the newly created didn’t show.

    Would be a great plugin if I could get it to work :(

    Reply
    1. andrew Post author

      Hello Carsten! Sorry for the delayed update as I’ve been busy with work and other things going on, but I’ve finally gotten around to updating the plugin to fix this bug. It took me a while to track it down but I finally narrowed it down. If you haven’t found another solution for managing sidebars hopefully you’ll give version 0.2 a look and see if it works for you. Thanks, Andrew.

      Reply
  3. Carsten

    Great plugin idea, just what I was looking for.

    Unfortunately, I can only create one additional sidebar with this addon and I don’t get this one to show.

    I made all the changes to the PHP files, but it just shows the default sidebar that I registered in PHP.

    Reply
    1. andrew Post author

      Hello Jamie, I’ve just updated with version 0.2 which will hopefully fix the issue for you. I’m not sure why it happened but when a new sidebar was created for the first time, it would create it with an index of “2”, which means additional sidebars would be saved over it. Finally found the problem and pushed a fix. Let me know if it fixes the problem for you.

      When I find the time I’ll have a bigger update which will allow you to select different archives, posts, etc. for displaying sidebars on. I know many other people have wanted that feature (and so have I). I’m also hoping to allow you to manage your *existing* theme sidebars on a per-page basis. More updates, too!

      Reply
  4. Joseph Tinari

    Hello, I love the plugin and it does exactly what i want. But, Is there a way to duplicate the sidebar for use on maybe lets say 20 pages i want instead of manually setting up each widget on each page after disabling the original sidebar? Thanks – JT

    Reply
  5. Magnus

    Hi Andrew ,
    Love your plugin – but…
    As Eamon said: I know html and css but php is a struggle.
    So – all looks good in Manage Sidbar – but it doesn´t show on the page I want them to.
    I get that with changing “” but what about “register_sidebar()”.
    Could you please explain?

    //Magnus

    Reply
    1. andrew Post author

      Hi Magnus,

      The plugin handles the register_sidebar() call for you. The only piece of code that you need to place in your theme is <?php dynamic_sidebar( apply_filters( 'ups_sidebar', 'primary' ) ); ?>. Everything is handled in the admin backend or by the plugin.

      Thanks,
      Andrew

      Reply
  6. Magnus

    Hi and tnx Andrew!
    It worked out.
    But… new problem :-/
    Now I only can make 2 different SidBars – when I try to setup the 3:rd it over wrights the second and I have 2 but the second with a new name…
    Confused :-/
    – Other ways it´s a nice pluggin :-)

    //Magnus

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>