WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 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:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.3
Component: Widgets Keywords: needs-patch
Focuses: Cc:

Description

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 (2)

#1 @westonruter
3 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
2 years ago

  • Keywords needs-patch added; close removed
  • Milestone changed from Awaiting Review to Future Release
  • Type changed from defect (bug) to enhancement
Note: See TracTickets for help on using tickets.