Make WordPress Core

Opened 8 months ago

Last modified 12 days ago

#59972 new defect (bug)

Clarify description of wp_script_add_data()

Reported by: crstauf's profile crstauf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Script Loader Keywords: needs-patch
Focuses: docs Cc:

Description

The function description does not include strategy as a possible value for $key. Suggest to adjust to indicate function is a wrapper for WP_Scripts::add_data(), and then add possible values conditional and strategy to WP_Scripts::add_data() function description or parameter description.

This documentation does not make it very clear that this can’t be used for adding arbitrary values attributes to the script tag. It only supports ‘conditional’ or, more recently, a “strategy” value.

For adding an alternate type attribute, for example, you’ll still need to use older strategies like the script_loader_tag filter.

See this StackExchange post for details.

Reported by @mrwweb via User Contributed Notes.

Change History (2)

#1 @sabernhardt
13 days ago

  • Component changed from General to Script Loader
  • Keywords needs-patch added

#2 @niravsherasiya7707
12 days ago

@crstauf I recommend updating the function name because wp_script_add_data might raise the question, "Which data?".

The purpose of this function is to add attributes to the script if wp_script_add_data matches the 'browser version' when the 'conditional' value is passed as $key or the strategy 'defer' or 'async' is used.

Note: See TracTickets for help on using tickets.