Limit reviews and TouristTrip schema

#1076558
  • Resolved David Grishaver
    Rank Math free

    Hi there!

    We run the PRO version! rainbowhelicopters.com here and we have hundreds of reviews on products. Is it advisable to limit them to 10 per product or some other number?

    if ( ! function_exists( 'limit_reviews_in_product_schema' ) ) {
        /**
         * Callback to limit reviews in the product schema to 10 entries.
         *
         * @param array $entity The Product schema data array.
         * @return array Modified schema data with at most 10 reviews.
         */
        function limit_reviews_in_product_schema( $entity ) {
         // Log when this function runs
         //error_log('RAINBOW SCHEMA FILTER: Product schema filter is running at ' . date('Y-m-d H:i:s'));
        
    
            // Only modify if there is a 'review' key with an array of reviews.
            if ( isset( $entity['review'] ) && is_array( $entity['review'] ) ) {
                // Limit the reviews array to the first 10 entries.
                $entity['review'] = array_slice( $entity['review'], 0, 10 );
            }
            return $entity;
        }
    }
    
    // Attach our function to Rank Math's product schema filter with a high priority.
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', 'limit_reviews_in_product_schema', 100, 1 );
    

    As this code will run on products only is there advisable code/hook/filter I can run that will add in the TouristTrip schema and populate it’s parameters. Any tips for this would be amazing.

    Best,
    Dave

Viewing 1 replies (of 1 total)
  • Hello,

    We apologize for the issue you’re facing regarding the review limits and the TouristTrip schema. Limiting reviews to a certain number, like 10, can be beneficial for performance and clarity, especially if you have hundreds of reviews. It helps keep the schema data concise and manageable, which can improve loading times and reduce potential errors with search engines.

    Your provided code snippet looks good for limiting the reviews in the product schema. Just ensure that you test it thoroughly to confirm it behaves as expected.

    Regarding adding the TouristTrip schema, you can use a similar approach by creating a function that populates the necessary parameters for the TouristTrip schema. Here’s a basic example of how you might structure that:

    if ( ! function_exists( 'add_tourist_trip_schema' ) ) {
        /**
         * Callback to add TouristTrip schema data.
         *
         * @param array $entity The Product schema data array.
         * @return array Modified schema data with TouristTrip details.
         */
        function add_tourist_trip_schema( $entity ) {
            // Check if this is a Tourist Trip product
            if ( isset( $entity['@type'] ) && $entity['@type'] === 'TouristTrip' ) {
                // Populate your TouristTrip parameters here
                $entity['touristType'] = 'Your Tourist Type'; // Example parameter
                // Add more parameters as needed
            }
            return $entity;
        }
    }
    
    // Attach our function to Rank Math's schema filter with a high priority.
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', 'add_tourist_trip_schema', 100, 1 );

    Make sure to replace 'Your Tourist Type' with the actual data you want to include. You can refer to the Schema.org documentation for more details on the parameters you can use.

    If you need further assistance or specific examples, feel free to reply to this ticket, and a human agent from our support team will be happy to help you out!

    Thank you for raising this concern!

    Sources:
    How to Use Product Schema for WooCommerce Products » Rank Math

    This is an automated reply from Rank Math Support Bot. If you need further assistance, please reply to this topic and a human support agent will reply to you shortly.

    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 1 replies (of 1 total)

The ticket ‘Limit reviews and TouristTrip schema’ is closed to new replies.