More flexible sidebar and widget management

I’d like to have a plugin for a flexible sidebar/widget management. In fact, I want to give a user the possibility to choose which sidebar should be displayed per page/post.

I know there are many sidebar plugins out there. Unfortunately, I haven’t found one which cover all my wishes. So I’d like to code this on my own. Which of the following possibilities do you find is the best and most flexible? Or do you have other approaches?

Posibilities

  1. Hardcode the register_sidebar calls in a plugin/functions.php and add a metabox for the post_edit.php, post_new.php screens.

    • Not that flexible. If a user has 100 pages and every page should have a different sidebar, the user has to register additional sidebars manually.
  2. Same as Nr.1 but use a generic sidebar template with conditional tags to display the widgets. We could also use the plugin Widget Logic for a more granular filtering in the backend.

    • Good for a programmer or experienced WordPress user, but not for a normal user. The conditional tags must be mapped in a friendly manner. Also is_page(id) could create problems on multilingual sites, where posts of a different language are stored with another id.
  3. A flexible-sidebars Custom Post Type. Every post in this CPT is used in a generic sidebar-template to display the given content. The sidebar is also selected within a custom metabox. The user can add content to the sidebar with the default WYSIWYG editor which is a big plus.

    • Not a „real“ sidebar. Therefore widgets couldn’t longer be added on the widgets-subpage in the admin panel. We have to create an own metabox for widget-assignments.
  4. Modify the widgets-subpage in the admin panel to create/register your own sidebars in WordPress. Also create a generic widget with a default WYSIWYG editor. Content with attachments could easily be added to the widget and draged to the new created sidebar.
    The user could then choose this sidebar with a drop-down field in a custom metabox in the post/page admin screens. To display the sidebar, we need also a generic sidebar-template.

Conclusion

From my point of view, Nr.4 should do the trick. Are there any other possibilities? Or does this already exists in a plugin?

Thanks for your reply

2 Answers
2

There’s a extension called “Widget Logic”. It adds a field to every sidebar widget in admin section where you can add a piece of php code that you can use to archive what you most likely need.

Its a bit cumbersome but works. For example you mention that for multilanguage site, you can still use “is_page” since you can also pass array for the function, like this: is_page(array(94,71,3)) .. With logic operators (and/or/not/xor) combined with you can archive any combination.

Leave a Comment