ACF\AI\GEO

GEO::render_jsonld_scriptpublic staticACF 6.8.0

Render a JSON-LD script tag with the provided data

Shared helper method for outputting JSON-LD structured data.

Method of the class: GEO{}

Returns

null. Nothing (null).

Usage

$result = GEO::render_jsonld_script( $jsonld_data );
$jsonld_data(array) (required)
The JSON-LD data array to output.

Changelog

Since 6.8.0 Introduced.

GEO::render_jsonld_script() code ACF 6.8.8

public static function render_jsonld_script( $jsonld_data ) {
	if ( empty( $jsonld_data ) ) {
		return;
	}

	/**
	 * Action fired before rendering JSON-LD script tag
	 *
	 * Allows developers to output custom schemas or capture the data.
	 *
	 * @param array $jsonld_data The JSON-LD data array.
	 */
	do_action( 'acf/schema/render_script', $jsonld_data );

	/**
	 * Filter to disable ACF's default JSON-LD output
	 *
	 * Return true to prevent ACF from outputting the JSON-LD script tag.
	 * Useful if you want to handle the output yourself via the action above.
	 *
	 * @param bool  $disable      Whether to disable default output. Default false.
	 * @param array $jsonld_data  The JSON-LD data that would be output.
	 */
	$disable_output = apply_filters( 'acf/schema/disable_output', false, $jsonld_data );

	if ( $disable_output ) {
		return;
	}

	// Output the JSON-LD script tag.
	echo "<script type=\"application/ld+json\">\n";
	echo wp_json_encode( $jsonld_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_UNESCAPED_UNICODE );
	echo "\n</script>\n";
}