apply_filters( "script_module_data_{$module_id}", array $data )
- Since
- 6.7.0
Filters data associated with a given Script Module.
Description
Script Modules may require data that is required for initialization or is essential to have immediately available on page load. These are suitable use cases for this data.
The dynamic portion of the hook name, $module_id, refers to the Script Module ID that the data is associated with.
This is best suited to pass essential data that must be available to the module for initialization or immediately on page load. It does not replace the REST API or fetching data from the client.
Compatibility
- WordPress
- since 6.7.0
- 6.7.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in every tracked release (6.7.10 to 7.1.3).
Parameters
$dataarray- The data associated with the Script Module.
Where this hook fires · 1
wp-includes/class-wp-script-modules.php:440WP_Script_Modules::print_script_module_data()
Source code
* initMyScriptModuleWithData( data ); * * @since 6.7.0 * * @param array $data The data associated with the Script Module. */ $data = apply_filters( "script_module_data_{$module_id}", array() ); if ( is_array( $data ) && array() !== $data ) { /* * This data will be printed as JSON inside a script tag like this: * <script type="application/json"></script> *Changelog
Introduced in 6.7.0. Unchanged from 6.7.10 through 7.1.3.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.10 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
- Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.