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
$contextarray
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.
Uses · 1
wp_json_encode()Encodes a variable into JSON, with some confidence checks.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/interactivity-api/interactivity-api.php, 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.