WordPress at Your Fingertips
function is not described

wc_esc_json() WC 3.5.5

Escape JSON for use on HTML or attribute text nodes.

No Hooks.


String. Escaped JSON.


wc_esc_json( $json, $html );
$json(string) (required)
JSON to escape.
True if escaping for HTML text node, false for attributes. Determines how quotes are handled.
Default: false


Since 3.5.5 Introduced.

Code of wc_esc_json() WC 6.1.1

function wc_esc_json( $json, $html = false ) {
	return _wp_specialchars(
		$html ? ENT_NOQUOTES : ENT_QUOTES, // Escape quotes in attribute nodes only.
		'UTF-8',                           // json_encode() outputs UTF-8 (really just ASCII), not the blog's charset.
		true                               // Double escape entities: `&` -> `&`.