wp_interactivity_data_wp_context( array $context, string $store_namespace =  ): string

In this article

Generates a data-wp-context directive attribute by encoding a context array.

Description

This helper function simplifies the creation of data-wp-context directives by providing a way to pass an array of data, which encodes into a JSON string safe for direct use as a HTML attribute value.

Example:

<div <?php echo wp_interactivity_data_wp_context( array( 'isOpen' => true, 'count' => 0 ) ); ?>>

Parameters

$contextarrayrequired
The array of context data to encode.
$store_namespacestringoptional
The unique store namespace identifier.

Default:''

Return

string A complete data-wp-context directive with a JSON encoded value representing the context array and the store namespace if specified.

Source

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.