Hello,
Thank you for contacting Rank Math support, and sorry for any inconvenience that might have been caused due to that.
Kindly refer to this filter code here to remove the datePublished and dateModified properties:
For your article schema:
add_filter( "rank_math/snippet/rich_snippet_article_entity", function( $entity ) {
unset( $schema['dateModified'] );
unset( $schema['datePublished'] );
return $entity;
});
The WebPage:
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
unset ($data['WebPage']['dateModified']);
unset ($data['WebPage']['datePublished']);
return $data;
}, 99, 2);
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Thanks for the reply. Can you help me to remove datePublished and dateModified properties from the entire website? Not a particular page but in future posts too. Also, where do I add the code?
Hello,
The code above should be applied to all of your pages upon saving it.
The filter should be added to your active theme’s functions.php file. Here’s another way to apply the filter using the rankmath.php file:
https://rankmath.com/kb/filters-hooks-api-developer/#adding-filters-and-hooks-in-rank-math-php
I hope that helps.
Thank you.
So, do I have to add both the filter codes one below the other in rankmath.php file? Anything else is required apart from these codes in rankmath.php file?
Hello,
Both filters can be added in the same place. Either you include them in the rank-math.php file of your child theme or in the functions.php file of your active theme. If you correctly inserted them, the outcomes would be the same.
However, we consistently advise our users not to add code to the active theme’s functions.php file. The reason behind for this is that, when you update your theme, you would lose the modified code and changes made, which could have a negative impact on your website. So, it’s always a good idea to make changes to the child theme or use third-party plugins.
To learn more about adding hooks and filters to your website in more detail and with visuals, please try visiting the following URL:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Hope that helps, and please do not hesitate to let us know if you need our assistance with anything else.
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.