Opened 12 years ago
Last modified 5 years ago
#29155 new enhancement
Widgets: is_active_widget returns true even when the widget is not displayed on specific page
| Reported by: | jeherve | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Widgets | Version: | 2.3 |
| Severity: | normal | Keywords: | needs-patch |
| Cc: | Focuses: |
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_widgetwill 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
@
11 years ago
- Keywords needs-patch added; close removed
- Milestone Awaiting Review → Future Release
- Type defect (bug) → enhancement
#3
@
5 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Yeah, that's probably not intuitive. The
is_active_widgetactually 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_sidebarand keep a log of the widgets that are actually rendered on the page, and then inwp_footeryou 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().