WP_Interactivity_API::add_load_on_client_navigation_attribute_to_script_modules
Adds the data-wp-router-options attribute to script modules that support client-side navigation.
This method filters the script attributes to include loading instructions for the Interactivity API router, indicating which modules can be loaded during client-side navigation.
Method of the class: WP_Interactivity_API{}
No Hooks.
Returns
Array. The modified script tag attributes.
Usage
$WP_Interactivity_API = new WP_Interactivity_API(); $WP_Interactivity_API->add_load_on_client_navigation_attribute_to_script_modules( $attributes );
- $attributes(required)
- .
Changelog
| Since 6.9.0 | Introduced. |
WP_Interactivity_API::add_load_on_client_navigation_attribute_to_script_modules() WP Interactivity API::add load on client navigation attribute to script modules code WP 6.9.1
public function add_load_on_client_navigation_attribute_to_script_modules( $attributes ) {
if (
is_array( $attributes ) &&
isset( $attributes['type'], $attributes['id'] ) &&
'module' === $attributes['type'] &&
array_key_exists(
preg_replace( '/-js-module$/', '', $attributes['id'] ),
$this->script_modules_that_can_load_on_client_navigation
)
) {
$attributes['data-wp-router-options'] = wp_json_encode( array( 'loadOnClientNavigation' => true ) );
}
return $attributes;
}