Support » Plugin: Display Widgets » is_active_sidebar not working with this plugin.

Viewing 6 replies - 1 through 6 (of 6 total)
  • In case anyone else is struggling with this, I wrote this function as an alternative to is_active_sidebar() for the Display Widgets plugin. The comments explain it all. Stick this in your functions.php file, and then use has_visible_widgets() instead of is_active_sidebar().

    /* The Display Widgets plugin doesn't update
     * is_active_sidebar() for hidden widgets.
     * This function tests dynamic_sidebar() to
     * see if it is empty. Use instead of
     * is_active_sidebar() to determine if the
     * sidebar has any widgets. Remember to
     * change back to is_active_sidebar() if no
     * longer using Display Widgets.
     */
    function has_visible_widgets( $sidebar_id ) {
    
        // First check if sidebar has any widgets
        if ( is_active_sidebar($sidebar_id) ) {
            // Use PHP output buffer to load
            // the sidebar into a variable
            ob_start();
            dynamic_sidebar($sidebar_id);
            $sidebar = ob_get_contents();
            ob_end_clean();
            // Return false if sidebar is empty
            if ($sidebar == "") return false;
        } else {
            return false;
        }
    
        // Return true if sidebar is not empty
        return true;
    
    }

    mattscottdesign, thank you thank you! I needed a way of adding a body class ONLY if a certain sidebar was explicitly present on each page. This allowed me to do it.

    Many thanks for following up and posting this solution.

    Mattscottdesign, thanks so much.
    @ SpankMarvin: would you mind to share your solution?

    I’d love to do something similar to what you described.
    Thanks in advance
    G.

    My code is here:

    http://pastebin.com/QHLSxvse

    Basically, it hooks into wp_head, runs the function above, and if it returns true, it adds a class to the body tag. This allows me to adjust the width of my content areas accordingly with CSS. There would be other more straightforward solutions but I had to work with this due to the way a developer had setup the sidebars to work.

    Hope this helps.

    J

    Awesome! Thanks so much… this makes the day!!

    is_active_sidebar() is now supported in v2.0. Enjoy!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘is_active_sidebar not working with this plugin.’ is closed to new replies.