Remove DatePublished from reviews in product schema

#853781
  • Resolved Mads Danmark
    Rank Math free

    Hi,

    I am having issues with Google showing a date in the meta description for my products. The date displayed comes from the DatePublished for the product reviews. I have removed the dates, but they are still in the product schema. I have tried the DatePublished in the schema with some of the codes your chatbot provides, but they do not work.

    Do you know a code that works?
    Here are the codes I’ve already tried to remove it with:

    <add_filter( ‘rank_math/schema/product’, function( $data ) {
    if ( isset( $data[‘review’] ) ) {
    foreach ( $data[‘review’] as &$review ) {
    unset( $review[‘datePublished’] );
    }
    }
    return $data;
    });>

    </add_filter( ‘rank_math/schema/woocommerce/review’, function( $review ) {
    unset( $review[‘datePublished’] );
    return $review;
    });>

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

    We apologize for the issue you are facing with the DatePublished showing in your product schema. Thank you for raising this concern.

    To remove the datePublished from the reviews in the product schema, you can use the following code snippet:

    add_filter( 'rank_math/schema/product', function( $data ) {
        if ( isset( $data['review'] ) ) {
            foreach ( $data['review'] as &$review ) {
                unset( $review['datePublished'] );
            }
        }
        return $data;
    });

    Make sure to place this code in your theme’s functions.php file or a custom plugin. This should effectively remove the datePublished from the reviews in your product schema.

    If you continue to experience issues, please reply to this ticket, and a human agent from the Rank Math Support team will assist you further.

    Thank you for your patience!

    Sources:
    Remove All Schema from Product Category Pages » Rank Math

    Hello,

    Thank you for your query and we are so sorry about the trouble this must have caused.

    Please try this code instead:

    add_filter( 'rank_math/json_ld', function( $data ) {
    	unset( $data['WebPage']['datePublished'] );
    	return $data;
    });
    
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
      unset( $entity['datePublished'] );
    	
    	if(isset($entity['review'])){
    		foreach($entity['review'] as $k => $rr){
    			unset($entity['review'][$k]['datePublished']);
    		}
    	}
    	return $entity;
    });

    You may refer to this guide on how to add filters to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how that goes. Looking forward to helping you.

    It worked. Thank you so much for your help!

    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.

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

The ticket ‘Remove DatePublished from reviews in product schema’ is closed to new replies.