Custom Sidebars Pro - Only show registered sidebar on specific template

Okay, you've stumped me.

I've registered a sidebar that has only one purpose - to be a replaceable widget container inside of a user-created Parallax section. All told, it works pretty well, unless I don't have the Parallax template selected. See the attached image.

Have you included a way to [a] only show the sidebars metabox if a sidebar is available and [b] make a specific sidebar only available to a specific page template?

I can probably write that functionality myself but I'd rather not. Am I missing an option?

  • Imperative Ideas

    Manual resolution --

    The following script checks the page template, then sets the display property of the named sidebar accordingly.

    (function($){
        $(function() {
            var etwPageTemplate = $('#page_template'),
                theLabel = $('#customsidebars-mb').find('label'),
                theOptions = $('#cs_replacement_parallax-sidebar');
    
            etwPageTemplate.change(function() {
                if ($(this).val() == 'custom-templates/pjax-parallax.php') {
                    theLabel.show();
                    theOptions.show();
                } else {
                    theLabel.hide();
                    theOptions.hide();
                }
            }).change();
        });
    })(jQuery);

    If you're hunting for this in the future, you'll also need to create and enqueue an admin-side script. Mine looks like this, adjust your values to suit --

    add_action('admin_enqueue_scripts', 'etw_admin_js');
    function etw_admin_js()
    {
        wp_enqueue_script('admin-js', get_bloginfo('stylesheet_directory').'/library/js/admin.js', array('jquery'));
    }
  • Vinod Dalvi

    Hi @Imperative Ideas,

    I hope you are well today and thanks for posting on the forum.

    Have you included a way to [a] only show the sidebars metabox if a sidebar is available and

    Currently the dropdowns in the sidebars metabox is only displays when you select any default sidebar as replaceable sidebar and if none selected then empty sidebars metabox is displayed having some information for the user so currently the empty sidebars metabox is used for displaying information to the users.

    [b] make a specific sidebar only available to a specific page template?

    I think you are talking about making a specific sidebar only available to a specific page template in the sidebars metabox.

    Currently this feature is not available in the plugin out of the box without custom coding.

    I will move this over to the features & feedback section. This way it can be considered for future development, and we can also see what other community members think about the feature request.

    Thanks for sharing the solutions in the WPMU DEV community. I hope it will help others.

    Thanks,
    Vinod Dalvi

  • Imperative Ideas

    Thanks for the reply Vinod.

    My script above actually needs more traps. I ended up deleting legitimate labels on other pages.

    What's going on is that I develop WordPress sites for Silicon Valley firms, and they tend to want an exceptionally smooth administrative experience. I can't walk a company like that through the process of when to use vs not use a specific feature - particularly when that feature includes a custom parallax page builder through ACF.

    A little more conditional control over where the sidebar becomes replaceable would be nice though.