Hello @rocketpig3,
Thank you for contacting the support.
You can use the following filter to remove that data from Schema:
https://rankmath.com/kb/filters-hooks-api-developer/#change-post-schema-data
But please stay advised that we do not recommend doing that as Google can still fetch that data from Sitemaps.
Hope that helps.
Thanks.
Is this correct? It doesn’t appear to be working.
/**
* Filter to change the schema data.
* Replace $schema_type with schema name like article, review, etc.
* @param array $entity Snippet Data
* @return array
*/
add_filter( “rank_math/snippet/rich_snippet_{$schema}_entity”, function( $entity ) {
unset( $schema[‘datePublished’] );
unset( $schema[‘datePublished’] );
return $entity;
});
Also, is there a way to remove the date from the sitemap? I’d like it to look like this: https://www.broadbandgenie.co.uk/sitemap-comparison.xml
Maybe using a sitemap made by another plugin?
Thanks
-
This reply was modified 5 years, 5 months ago by
rocketpig3.
-
This reply was modified 5 years, 5 months ago by
rocketpig3.
-
This reply was modified 5 years, 5 months ago by
rocketpig3.
-
This reply was modified 5 years, 5 months ago by
rocketpig3.
-
This reply was modified 5 years, 5 months ago by
rocketpig3.
Hello @rocketpig3
Please use the following code to remove datePublished from the Article Schema:
add_filter( "rank_math/snippet/rich_snippet_article_entity", function( $entity ) {
unset( $schema['datePublished'] );
return $entity;
});
To remove date from the Sitemap, you can use following filter code:
`add_filter( ‘rank_math/sitemap/entry’, function( $url, $type, $object ) {
if ( isset( $url[‘mod’] ) ) {
unset( $url[‘mod’] );
}
return $url;
}, 10, 3 );
Hope that helps. Thank you.
Hi again,
Thanks for that.
I tried the filter to remove datePublished by putting it in my child theme’s functions.php. However “datePublished”:”2020-01-02T07:00:01+00:00″ remains in the source code after clearing my site and browser cache. The site I am testing it on is the same one as in the original post.
The code looks like this: https://i.imgur.com/TEuFZVI.png
Similar question: can you use the same code but with dateModified instead of datePublished to remove dateModified?
Thanks
-
This reply was modified 5 years, 5 months ago by
rocketpig3.
Hello @rocketpig3
The code we provided should remove the datePublished & dateModified from the Article Schema.
You must be seeing those 2 properties in the WebPage entity.
Here is a complete code to remove it from both Article & WebPage entity:
add_filter( 'rank_math/snippet/rich_snippet_article_entity', function( $entity ) {
unset( $entity['datePublished'] );
unset( $entity['dateModified'] );
return $entity;
} );
add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
if ( ! isset( $data['WebPage'] ) ) {
return $data;
}
unset( $data['WebPage']['datePublished'] );
unset( $data['WebPage']['dateModified'] );
return $data;
}, 99, 2 );
Hope that helps.
@rankmath – this last function is not working for me. I wish it was. A page example is is https://madisonheightsurgent.care/urgent-care-berkley-mi and I ran it through here – https://search.google.com/test/rich-results.
Hello @ponderconsulting
Thank you for your message.
view-source:https://madisonheightsurgent.care/urgent-care-berkley-mi
It seems like some other SEO plugin is active on your website.
Also, please open a new support topic so we can assist you better:
https://wordpress.org/support/plugin/seo-by-rank-math/#new-topic-0
Looking forward to helping you.