change product description schema

#37561
  • Resolved Roberto
    Rank Math business

    Hello,
    I would like to understand, if automatically, I can provide structured data as a description, the long description of woocommerce instead of the short description that today automatically uses.
    Roberto

    • This topic was modified 4 years, 1 month ago by Roberto.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math today.

    Yes this is possible but you would need to write some custom code to get the value of the long description and pass it to the description attribute of the product schema.
    You can hook into the following filter to achieve this:

    /**
     * Filter to modify Products schema
     *
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
       ;
        return $entity;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​

    Roberto
    Rank Math business

    Thanks for the reply,

    but the custom code where should I put it in the functions.php file of thema child?

    Do I need to add anything to replace the short product description with the long product description?

    thanks,
    Roberto

    Hello,

    Thank you for contacting Rank Math today.

    The code would need to go to your theme’s functions.php or a child theme’s functions.php file if this is active. The code also needs to be adopted to your use case as shown below:

    /**
     * Filter to modify Products schema
     *
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        global $product;
        $product_full_description = $product->get_description();
        if($product_full_description){
           $entity['description'] = $product_full_description;
        }
        return $entity;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​

    Roberto
    Rank Math business

    Ciao Michael,
    thanks for your answer, now I will try it now.
    I would also have another need.
    I wish I could enter other structured data as schema.org suggests.
    For the @type Recipe I would like to add other property like: recipeIngredient; recipeInstructions; suitableForDiet.
    Can I implement them with Rank Math?

    Thanks,
    Roberto

    Hello,

    Thank you for contacting Rank Math today.

    I am afraid that the schema does not allow addition of other fields but you can disable the Rank Math schema on the page and then generate your own custom schema with these attributes and then add it to the page by using the following Rank Math 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);

    Looking forward to helping you. 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 5 replies - 1 through 5 (of 5 total)

The ticket ‘change product description schema’ is closed to new replies.