add custom field in rich snippet

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

    Thank you for contacting Rank Math today.

    You can extend the software review snippet with your own custom data by making use of the following filter:

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

    I hope this info helps. Thank you.

    ​​​​​​

    how to use this? Could yoou please elaborate

    Hi there,

    Thanks for the follow up.

    Here is an example of how you can generate your custom data and output it as SoftwareApplication schema:

    /**
     * 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 ) {
    	$entity = [
    			'@context'            => 'https://schema.org',
    			'@type'               => 'SoftwareApplication',
    			'name'                => 'Custom data',
    			'description'         => get_post_meta($post_id,$meta_key,true), //an example of how to get custom field data and assign it to the 'description'
    			'operatingSystem'     => '',
    			'applicationCategory' => '',
    			'offers'              => [
    				'@type'         => 'Offer',
    				'price'         => '',
    				'priceCurrency' => '',
    			],
    			'aggregateRating'     => [
    				'@type'       => 'AggregateRating',
    				'ratingValue' => '',
    				'ratingCount' => '',
    			],
    		];
    	return $entity;
    }, 10, 2);

    You can make use of the get_post_meta() function to grab the data from the custom fields and assign it to various elements in the data array.

    I hope this info helps. Thank you.

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

You must be logged in to reply to this ticket.