How to remove the date published and date modified schema from the Article schema (posts) and WebPage schema (pages and posts) in the Yoast SEO plugin for WordPress

Published: October 23, 2021 | Last Modified: October 23, 2021

I was contacted a few days ago by a fellow WordPress warrior (hello Dan) asking if it's possible to remove the date published (datePublished) and date modified (dateModified) schema from the Article schema (posts) and WebPage schema (posts and pages) in the Yoast SEO plugin for WordPress. The answer is yes, you can do this using the Yoast API.

The first thing to do is to put the Yoast SEO plugin into development mode. This makes the schema easier to read when you view the source and helps when debugging. To do this, add the code snippet below to your theme's functions.php:

add_filter( 'yoast_seo_development_mode', '__return_true' );

Make sure to remove or comment out this code on the production site, it's just for debugging/development/staging sites.

At the time of writing this is what the article and webpage schema looks like on a WordPress post on this website. Note both WebPage and Article output the datePublished and the dateModified:

"@type": "WebPage",
"@id": "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/#webpage",
"url": "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/",
"name": "How to Hide / Protect Email Addresses on WordPress Websites | JV",
"isPartOf": {
    "@id": "https://jodyvanv.com/#website"
},
"datePublished": "2018-08-08T12:54:59+00:00",
"dateModified": "2018-11-27T13:40:18+00:00",
"inLanguage": "en-GB",
"potentialAction": [
    {
        "@type": "ReadAction",
        "target": [
            "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/"
        ]
    }
]

"@type": "Article",
"@id": "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/#article",
"isPartOf": {
	 "@id": "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/#webpage"
},
"author": {
	 "@id": "https://jodyvanv.com/#/schema/person/628d076fe5ee15b9eec817c8e4ee18cd"
},
"headline": "How to Hide / Protect Email Addresses on WordPress Websites",
"datePublished": "2018-08-08T12:54:59+00:00",
"dateModified": "2018-11-27T13:40:18+00:00",
"commentCount": 0,
"mainEntityOfPage": {
	 "@id": "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/#webpage"
},
"publisher": {
	 "@id": "https://jodyvanv.com/#/schema/person/628d076fe5ee15b9eec817c8e4ee18cd"
},
"keywords": "Wordpress Core",
"articleSection": "Wordpress",
"inLanguage": "en-GB"

Remove the date published and date modified schema from the Article schema (posts)

To do this, add the following code snippet to your theme's functions.php:

/**
 * Remove date published and date modified from the Yoast SEO plugin schema
 *
 * @param array $graph_piece Yoast schema pieces.
 *
 * @return array
 */
function vanv_remove_published_modified_dates( $graph_piece ) {

	unset( $graph_piece['datePublished'], $graph_piece['dateModified'] );

	return $graph_piece;

}

add_filter( 'wpseo_schema_article', 'vanv_remove_published_modified_dates' );

Remove the date published and date modified schema from the WebPage schema (posts and pages)

To do this, add the following code snippet to your theme's functions.php:

/**
 * Remove date published and date modified from the Yoast SEO plugin schema
 *
 * @param array $graph_piece Yoast schema pieces.
 *
 * @return array
 */
function vanv_remove_published_modified_dates( $graph_piece ) {

	unset( $graph_piece['datePublished'], $graph_piece['dateModified'] );

	return $graph_piece;

}

add_filter( 'wpseo_schema_webpage', 'vanv_remove_published_modified_dates' );

Remove the date published and date modified schema from both the WebPage schema (posts and pages) and the Article schema (posts)

To remove both the datePublished and dateModified schema from both schema types (Article and WebPage), add the following code snippet to your theme's functions.php:

/**
 * Remove date published and date modified from the Yoast SEO plugin schema
 *
 * @param array $graph_piece Yoast schema pieces.
 *
 * @return array
 */
function vanv_remove_published_modified_dates( $graph_piece ) {

	unset( $graph_piece['datePublished'], $graph_piece['dateModified'] );

	return $graph_piece;

}

add_filter( 'wpseo_schema_webpage', 'vanv_remove_published_modified_dates' );
add_filter( 'wpseo_schema_article', 'vanv_remove_published_modified_dates' );

With both schema removed, the schema on this website now looks like this

"@type": "WebPage",
"@id": "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/#webpage",
"url": "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/",
"name": "How to Hide / Protect Email Addresses on WordPress Websites | JV",
"isPartOf": {
    "@id": "https://jodyvanv.com/#website"
},
"inLanguage": "en-GB",
"potentialAction": [
    {
        "@type": "ReadAction",
        "target": [
            "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/"
        ]
    }
]

"@type": "Article",
"@id": "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/#article",
"isPartOf": {
	 "@id": "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/#webpage"
},
"author": {
	 "@id": "https://jodyvanv.com/#/schema/person/628d076fe5ee15b9eec817c8e4ee18cd"
},
"headline": "How to Hide / Protect Email Addresses on WordPress Websites",
"commentCount": 0,
"mainEntityOfPage": {
	 "@id": "https://jodyvanv.com/how-to-hide-protect-email-addresses-on-wordpress-websites/#webpage"
},
"publisher": {
	 "@id": "https://jodyvanv.com/#/schema/person/628d076fe5ee15b9eec817c8e4ee18cd"
},
"keywords": "Wordpress Core",
"articleSection": "Wordpress",
"inLanguage": "en-GB"

Full props to https://wp-snippet.dev/snippet/remove-published-date-from-yoast-schema/ for providing the snippet the above article is based on.