-
Hello,
My other ticket was closed prematurely because the code that was given to me did not work.
In the original ticket located here: https://support.rankmath.com/ticket/adding-thumbnailurl-to-schema-markup/
I was trying to get the ‘thumbnailUrl’ to display the featured image of the post.
The code which was suggested was:
/** * Collect data to output in JSON-LD. * * @param array $unsigned An array of data to output in json-ld. * @param JsonLD $unsigned JsonLD instance. */ add_filter( 'rank_math/json_ld', function( $data, $jsonld ) { if(is_single()){ // If it is a post // Get its feature post URL: // grab the url for the full size featured image $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); // Now add that URL to the ThumbnailURL schema $data['thumbnailURL'] = [ $featured_img_url ]; return $data; } return []; }, 10, 2);
But this code gave an Unspecified Type error as shown in the screenshot link below. I think it was because this schema markup was not placed INSIDE the article schema but outside of it.
https://snipboard.io/gu7eIl.jpg
Is it possible to change this code so that it places the ‘thumbnailUrl’ inside the article schema?
Please advise.
Regards.
You must be logged in to reply to this ticket.