Opened 11 years ago
Last modified 3 years ago
#29155 new enhancement
Widgets: is_active_widget returns true even when the widget is not displayed on specific page
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.3 |
Component: | Widgets | Keywords: | needs-patch |
Focuses: | Cc: |
Description
Steps to reproduce:
- Activate Twenty Eleven
- In Appearance > Widgets, add a widget to the Showcase widget area (only displayed on pages using the Showcase Page Template)
- Load your home page.
is_active_widget
will return true for that widget, even if it is not displayed on the home page.
It seems like it would be nice if is_active_widget
only returned true when the widget was actually displayed on the page. I'm not sure how to do that, though.
Change History (3)
#2
@
9 years ago
- Keywords needs-patch added; close removed
- Milestone changed from Awaiting Review to Future Release
- Type changed from defect (bug) to enhancement
#3
@
3 years ago
Just ran across an issue with WooCommerce widget's CSS loading on every page. Some function to check if widget is active on the current page would help a lot to load CSS conditionally thus improving WordPress performance. There are some solutions now but they are not easy enough to implement.
Maybe it would make sense to add a performance focus to this ticket?
Note: See
TracTickets for help on using
tickets.
Yeah, that's probably not intuitive. The
is_active_widget
actually returns true if the widget is assigned to a sidebar, not whether it was actually rendered on the page. To do that, you' would currently need to add an action fordynamic_sidebar
and keep a log of the widgets that are actually rendered on the page, and then inwp_footer
you could do something with them. This is what Widget Customizer is doing, see WP_Customize_Widgets::tally_sidebars_via_dynamic_sidebar_calls().A new function would be needed with different semantics than
is_active_widget()
, likeis_widget_displayed()
.