WidgetOptions / widget-options

Additional Widget options for better widget control. Available on
https://widget-options.com/
GNU General Public License v3.0
34 stars 16 forks source link

Support for is_active_sidebar() #15

Closed dotherightthing closed 7 years ago

dotherightthing commented 7 years ago

The Wordpress function is_active_sidebar() can be used to check whether any widgets are loaded into a sidebar.

When a widget is loaded into the sidebar but is hidden via Widget Options, I expectis_active_sidebar()to return false.

Currently it returns true - is_active_sidebar() treats a hidden widget as an active widget.

Can you inform Wordpress that a hidden widget is not active?

if ( is_active_sidebar('sidebar-1') ) {
// if there are some widgets loaded into the sidebar AND they are not hidden via Widget Options
  get_sidebar();
}
else {
// else no widgets loaded into sidebar, or the ones that are loaded are hidden via Widget Options
}

Thanks, Dan

phpbits commented 7 years ago

@dotherightthing the fix for the issue has been added on the develop branch. In which you can also download directly here and let me know how it goes. My apology for late response.

Cheers, Jeffrey

Anna-Webdesign commented 7 years ago

Hello!

I think I have the same issue here :(

If I don't select any widgets for a page there still is an empty space - I think if the sidebar turns up false the problem will be solved! I tried the download - but that did not make any change.

Can you help me with this problem?

Kind regards, Anna-Webdesign

dotherightthing commented 7 years ago

@phpbits Thanks for the update. I can't replicate my original scenario as the project has moved on, but I did a quick test and can replicate the problem in version 3.3.2 - but not in the linked version 3.4 thanks.

This is my sidebar setup (sidebar.php from twentysixteen). The fix prevents the #secondary container from being output, if there are no widgets assigned to 'Sidebar'.

<?php if ( is_active_sidebar( 'sidebar-1' )  ) : ?>
    <aside id="secondary" class="sidebar widget-area" role="complementary">
        <?php dynamic_sidebar( 'sidebar-1' ); ?>
    </aside><!-- .sidebar .widget-area -->
<?php endif; ?>
phpbits commented 7 years ago

@dotherightthing Sounds perfect! I've also got handful of other users that tested it out and seems to be working as expected : https://wordpress.org/support/topic/honor-is_active_sidebar-conditional-when-using-show-on-checked/ . This will be included on the next update along side with brand new features and I hope you'll love them. Thanks!

Cheers, Jeffrey

phpbits commented 7 years ago

@Anna-Webdesign That will be depending on the theme you are using. If the theme is not using is_active_sidebar() condition to change the template to a full width when empty then there will be a blank space on the page. Thanks!