Adding “thumbnailUrl” to Schema Markup

#85151
  • Resolved Artem Rev
    Rank Math free

    Hello,

    I am pretty new to the coding part of things in SEO related matter.

    I want to add the “thumbnailUrl” as a schema markup to all my articles. I want the “thumbnailUrl”, the actual URL be my featured image.

    Now i know that I can use: https://rankmath.com/kb/filters-hooks-api-developer/#extend-json-ld-data this part, but I have no idea how it works.

    So, if possible, I just want to guidance here.

    I am assuming what i need is something like this?

    /**
    * 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 ) {
    	'thumbnailUrl' => 'the_post_thumbnail_url()'}
    	return [];
    }, 10, 2);

    Please advise if possible. It would be greatly appreciated! And I will be able to go from here and add more if needed. But at least ill have an example.

    Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,

    Thank you for contacting Rank Math today.

    You can use an online schema generator such as this one: https://technicalseo.com/tools/schema-markup-generator/ to generate the schema that you would like to use and pass this to the filter as shown in this example:

    /**
    * 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_singular('listing')){
    	$data['Organization'] = [
    			'@context' => 'https://schema.org',
    			'@type'    => '',
    			'@id'      => '',
    			'name'     => '',
    			'url'      => '',
    			'sameAs'   => '',
    		];
    	return $data;
    	}
    	return [];
    }, 10, 2);

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello Michael,

    Thank you for the reply.

    The issue with the link you gave is that it will be specific to each article.

    I wanted to use a WordPress hook (I think it’s called) in order to pass the same schema markup for each article. In this case, for each article to have the schema markup “thumbnailURL” take the URL of the featured image.

    Please advise.

    Thank you in advance.

    Alberto
    Rank Math business

    Hello,

    You could modify the code my colleague shared. You need to check if you are in a post, in that case, get the featured image URL and then add it to the Schema with the code my colleague shared.

    Looking forward to help you.

    Hello,

    That’s the thing. I am not sure how to modify this properly.

    I will be in a post but this needs to apply to all posts. So that’s why I am figuring that I need to use a WordPress hook to make this work.

    Could you please at least guide me if the one I am using is right?

    Alberto
    Rank Math business

    Hello,

    This would be a little guide of what you should do:

    /**
    * 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);

    Looking forward to help you.

    This is amazing! Thank you so much, I would have never figured this out on my own. I will test this and get back to you.

    You guys are always so helpful!

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)

The ticket ‘Adding “thumbnailUrl” to Schema Markup’ is closed to new replies.