Display Widgets
[resolved] is_active_sidebar not working with this plugin. (7 posts)

  1. carlosdevia
    Posted 2 years ago #

    When i use this plugin to hide some widgets in a sidebar the function is_active_sidebar still says that the sidebar is active, even when it doesn't have any widget active using this plugin.


  2. mattscottdesign
    Posted 2 years ago #

    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
            $sidebar = ob_get_contents();
            // Return false if sidebar is empty
            if ($sidebar == "") return false;
        } else {
            return false;
        // Return true if sidebar is not empty
        return true;
  3. SpankMarvin
    Posted 1 year ago #

    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.

  4. Giorgio25b
    Posted 1 year ago #

    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

  5. SpankMarvin
    Posted 1 year ago #

    My code is here:


    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.


  6. Giorgio25b
    Posted 1 year ago #

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

  7. Steph Wells
    Plugin Author

    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Display Widgets
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic