Make WordPress Core

Opened 10 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: jeherve's profile jeherve Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.3
Component: Widgets Keywords: needs-patch
Focuses: Cc:


Steps to reproduce:

  1. Activate Twenty Eleven
  2. In Appearance > Widgets, add a widget to the Showcase widget area (only displayed on pages using the Showcase Page Template)
  3. 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)

#1 @westonruter
10 years ago

  • Keywords close added
  • Version changed from 3.9.1 to 2.3

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 for dynamic_sidebar and keep a log of the widgets that are actually rendered on the page, and then in wp_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(), like is_widget_displayed().

#2 @wonderboymusic
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 @titsmaker
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.