/**
 * Removed published date from generate Schema.org in Yoast.
 *
 * @param array $graph_piece Yoast schema pieces.
 *
 * @return array
 */
function dorzki_remove_published_date( $graph_piece ) {

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

	return $graph_piece;

}

add_filter( 'wpseo_schema_webpage', 'dorzki_remove_published_date' );

How to use it?

Usually adding functionality to a WordPress site is by creating a plugin.
However you can simply copy the code and paste it in your child theme’s functions.php file at the end of the file, just before ?>.

For JavaScript code you will need to add them to your theme’s main JavaScript file.

Having issues with the code?

If the code doesn’t work or you get an error please let us know in the comments section.
We will do our best to fix it as-soon-as-possible and update the code on this page.

Comments

  1. Sam

    Why would I want to removed the published date?

    Reply
    1. Dor Zuberi

      Hi Sam,
      It is related to SEO, Google ranking is based on the date for the page, if the page wasn’t updated for two years (for example) it will be ranked lower than newer pages.

      This is not an exact science, but this is in general…

Leave a Reply