sidebar visibilty filtered by custom taxonomy


I’m trying to figure out if this plugin can help me with a particular set up that I need for a client.

We’re looking to have different sidebars for each section. Sections are organized using a custom taxonomy.

I see that I can set a sidebar to subsitute another one when the viewed page (actually a post) is within a specified post-category.

Is there a way to add the option to filter by my custom taxonomy, in order to swap the sidebar only if the page is in a specified “section” (term of my custom taxonomy).

I can code, so if you tell me what to do I can edit the plugin code and/or add code snippets. :wink:



  • Michelle Shull
    • DEV MAN’s Apprentice

    Hi, Andrea!

    First off, I’m not a coder, so I’m not sure I can help re-write the plugin, but I think we should be able to make it work without touching the code. That’s a good thing, because it would be a pain to add changes each time Custom Sidebars Pro updates, which is pretty frequently.

    Can you explain a bit more about how you’re using the custom taxonomy? Is it working in the same way as a category (hierarchical) or as a tag (non-hierarchical)? Do you have parent and child “sections”?

    The easiest option, from the info I have now, is to set the sidebar at the post level. Since each item in your “sections” is actually a single post, I’m assuming they’re created with the post editor? If so, you can select the sidebar you want that post to have right in the post editor.

    Looking forward to hearing back from you!

  • Andrea
    • The Crimson Coder

    Hi Michelle,

    thank you for your reply.

    the “section” taxonomy is for “pages” post-type.

    it’s hierarchichal, and only 1st level terms, no childs.

    I’ve already spotted the fact that I could just set which sidebar I want to use in each single page editor, but we have a lot of pages, so that’s going to be a bit painful..

    I’ve also seen that I could set each widget in the alternative sidebar, to be visible only in a specific “section” taxonomy. so one solution could be:

    – set the sidebar to be swappable

    – creating an alternative sidebar, but don’t set any location auto swapping

    – in the alternative sidebar, create widgets for all the sidebars of all the sections, setting their visibility only for the related section.

    – in the pages editor of each page, select manually to display the “alternative sidebar” rather than the original one.

    in this way, despite all sections pages displays the same “alternative sidebar”, in each of them we’ll have only their specific widgets (set to be visible in that “section” taxonomy).

    the downside, as I said is having to manually set the alternative sidebar.

    The point is that, as there is the chance to set the widget visibility filtering by custom taxonomy, I am wondering if it’s so difficult to allow them in the sidebar’s location as well..



  • Michelle Shull
    • DEV MAN’s Apprentice

    Hi there, Andrea!

    I can definitely ask the developer for some feedback here, but first, would you mind letting me confirm what you’re seeing from your site? If this is ok, just grant me temporary admin access to your site by clicking “Grant Access” button in the WPMU DEV Dashboard Settings from the following path and reply on this thread after granting it?

    Admin -> WPMU DEV -> Support -> Support Access Tab

    If you have not installed WPMU DEV Dashboard plugin yet, kindly do that here : and then allow access as per the above process.


  • Andrea
    • The Crimson Coder

    Hello Michelle,

    I’m sorry but I don’t see any reason for this at the moment. I have no issues with the plugin and I don’t need someone to check the site nor the plugin.

    I just want to know if there is the possibility to edit the code in a fairly easy way, in order to allow to choose custom taxonomy as coniditional to display the alternative sidebar (at now you can set a sidebar to be swapped if the post is within a post-category, but not custom-tax. and you can set the visibility of a widget filtering by post cat or custom taxonomy. that’s what I need to have in the sidebar swapping conditions).

    if this is feasible without too much editing, I’d like to be pointed to the right file and functions, maybe with a couple of suggestions. then I can edit the code on my own.



  • Andrea
    • The Crimson Coder

    Hello Michelle,

    I am sorry to bothering you but I have the client pressing for me implementing a solution for his needs.

    so I really need to know at least if this is feasible, otherwise tomorrow I will have to start developing this functionality within the template files without using the plugin. but I’d really prefer to use the plugin if possible because it will allow my client for easy future additions of categories (sections terms) and alternative sidebars.



  • Philipp Stracker
    • The Crimson Coder

    Hey Andrea,

    you have already figured out what we would recommend you to do in this case: If possible use the Widget-Visibility to show widgets for specific taxonomy terms.

    This kind of filter does not yet exist on the sidebar-location level, as it opens room for many conflicts (e.g. which sidebar to choose when 2 or more sections are selected for the same page).

    However, we have added this task to our roadmap and will define/implement a way to select a sidebar for custom taxonomies in the future.

    In the current plugin we provide a custom filter that allows you to define your own replacements.

    Here is an usage-example:

    add_filter( 'cs_replace_sidebars', 'my_custom_replacement' );
    function my_custom_replacement( $replacements ) {
    global $post;

    if ( /* $post is in section */ ) {
    $replacements['sidebar-1'] = array(
    'cs-1', // ID of the custom sidebar to display.
    'custom', // always 'custom'
    -1, // always -1

    return $replacements;

    Where we use ‘cs-1’ in the example you can use any existing sidebar-ID. All Custom Sidebars will start with ‘cs-‘ (the actual ID is not displayed anywhere, but you can find it in the export-file, or when looking at the page source/network traffic of the widget page, …:wink:. Of course you can also use any theme sidebar-ID for replacement.

    Let us know if this works for you or if we can help you with anything else :slight_smile:

    Thanks, Philipp

  • Andrea
    • The Crimson Coder

    Hi Philipp!

    that looks very interesting, thanx!

    unfortunately I’ve developed an alternative way of achieving what I needed without using the plugin, so I’m not going to use it this time.

    I’ve created a function which register automatically one sidebar for each section. so if the client create a new section, he will automatically have a new sidebar available.

    then I’ve made a code in the template which checks if the page has a section-term set, and if yes it displays the sidebar with the same name.

    also I’ve made another taxonomy for alternative sidebars, with the same function that registers one sidebar for each term.

    then if the client adds one term in this taxonomy and set it to a page, the code will pick and display the related sidebar, rather than using the section sidebar (or the default one). so a page could be within a section but have a specific alternative sidebar. :slight_smile:

    anyway, it’s very good to know about this hook, I will surely take advantage of it in one of my future projects.

    p.s. I would address to you one thing I found a bit annoying of the plugin. when you go to the widgets section, the rightside of the screen is a frame when the plugin is installed. I am not sure if there is a reason for it, but the scrolling within that frame is very very slow, so you have to roll your mouse wheel like crazy, just to go down an inche.. it’ll be great if this could be sorted in the future versions. :wink:

    thank you very much!


  • Philipp Stracker
    • The Crimson Coder

    Thanks for the feedback :slight_smile:

    Could you let us know which browser/OS you are using?

    I’m mostly using latest version of Google Chrome on a Mac and sometimes Windows 7 and did not yet have any issue with the scrolling on the Widgets page.

    The scrollbar on the right side is created via the javascript plugin “tiny-scrollbar”, so maybe other javascripts that are loaded on your WordPress installation cause this issue?

    Would be happy for a short feedback so we know what to test and look out for.


  • Andrea
    • The Crimson Coder

    I am using Firefox 33.1 on a win8 OS (I have to update windows though..).

    now that you have said it, I’ve tried to login using chrome and the scrolling works fine there. so it’s something related to firefox, or at least to that very version of it.

    I hope to have been helpful. :slight_smile:



Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.