I’m trying to remove date properties from Article schema generated by the Yoast SEO plugin.
In their developer docs the wpseo_schema_article
filter is set as an example for manipulating with Article graph piece. However even with this type="application/ld+json"
:
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Article",
"mainEntityOfPage":{
"@type":"WebPage",
"@id":"https://www.myproscooter.com/etwow-electric-scooters-review/"
},
"headline":"E-Twow Electric Scooters 2021 Review",
"image":{
"@type":"ImageObject",
"url":"https://www.myproscooter.com/wp-content/uploads/2020/12/elek-scoot.jpg",
"width":700,
"height":400
},
"datePublished":"2020-12-08T08:52:13",
"dateModified":"2021-01-12T11:30:10",
"author":{
"@type":"Person",
"name":"Jason"
},
"publisher":{
"@type":"Organization",
"name":"MyProScooter",
"logo":{
"@type":"ImageObject",
"url":"https://www.myproscooter.com/wp-content/uploads/2021/01/MPS-Logo-228x60.png"
}
}
}
</script>
When I try to access and manipulate data like this:
add_filter( 'wpseo_schema_article', 'remove_article_dates' );
function remove_article_dates( $data ) {
file_put_contents(WP_CONTENT_DIR.'/helper-seo.txt','DATA PRE FILTER: '.print_r($data,true),FILE_APPEND);
unset($data['datePublished']);
unset($data['dateModified']);
return $data;
}
Nothing gets logged into helper-seo.txt nor do dates get unset in the Article schema; as if the filter is ignored totally.
What’s more confusing is that manipulation with dates in Webpage Schema works and is similar to the above:
add_filter( 'wpseo_schema_webpage', 'remove_webpage_dates');
function remove_webpage_dates( $data ) {
unset($data['datePublished']);
unset($data['dateModified']);
return $data;
}
The other stuff I’ve tried include:
add_filter( 'wpseo_schema_article_date_published', '__return_false' );
add_filter( 'wpseo_schema_article_date_modified', '__return_false' );
Which isn’t reflecting into Article schema at all. How to remove these properties sucessfully?
3
Answers
i am using this code, it will work
Try this exact code. I’m sure it will work for you. This cleared my problems at least.
None of those solutions worked for me, and I finally had to modify the Yoast plugin file wordpress-seosrcpresentersopen-grapharticle-modified-time-presenter.php and change line 32
return $this->presentation->open_graph_article_modified_time;
to this insteadreturn null;
and yes I realize that’ll get overwritten by future plugin updates.