Hello,
We apologize for the issue you are facing with the date snippets appearing in your Google Rich Snippets after customer reviews. Thank you for following up on this matter.
To adjust the provided snippet to also remove the datePublished
from product reviews, you can modify the filter to target the review schema specifically. Here’s an updated version of your code:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
if ( is_product() ) {
unset( $data['WebPage']['dateModified'] );
unset( $data['WebPage']['datePublished'] );
// Check if there are reviews and unset their datePublished
if ( isset( $data['Product']['review'] ) ) {
foreach ( $data['Product']['review'] as &$review ) {
unset( $review['datePublished'] );
}
}
return $data;
}
return $data;
}, 9999, 2);
This code checks if there are any reviews associated with the product and removes the datePublished
from each review.
Please test this updated snippet and let us know if it resolves the issue. If you have any further questions or need additional assistance, feel free to reply to this ticket. We’re here to help!
Sources:
Removing Schema From Your Posts & Pages » Rank Math
Unfortunately that solution does not seem to work.
datePublished persists for the reviews even with that code.
Hello,
In order to remove the datePublished
from your review snippet, you can use the following filter code on your website:
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;
});
Let us know how it goes. Looking forward to helping you.
Thank you.
That did the trick, thank you!
Hello,
We are glad to know that this issue has been resolved. Thank you for letting us know.
This ticket will be closed now, but you can always open a new one if you have any other questions or concerns. We are here to help you with anything related to Rank Math.
We appreciate your patience and cooperation throughout this process.
Thank you for choosing Rank Math.