Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to translate schema from schema.org generate by Yoast plugin

On this example we use a filter to translate some entry from our schema based on this doc : https://developer.yoast.com/features/schema/api/

add_filter( 'wpseo_schema_graph', 'wg_schema', 10, 2 );

function wg_schema( $data, $context ) {
	
	foreach ( $data as $key => $value ) {
        if ( $value['@type'] === 'WebPage' || $value['@type'] === 'WebSite') {
            $data[$key]['@id'] = weglot_get_current_full_url();
			$data[$key]['url'] = weglot_get_current_full_url();
			$data[$key]['inLanguage'] = weglot_get_current_language();
        }
		
		if ( $value['@type'] === 'ImageObject' || $value['@type'] === 'primaryImageOfPage') {
			$data[$key]['inLanguage'] = weglot_get_current_language();
        }
    }
		
    return $data;
}

Last updated