Hide from the Schema datePublished and dateModified only in certain posts
-
Hello,
I need to remove datePublished and dateModified from Schema in order to Google not show dates in certains posts.
I tried to use the following code in functions.php, but it is not working (in this case i need to apply in the single posts with ID 531 and 141):
—————————————————————————————————
function vanv_remove_published_modified_dates( $graph_piece ) {
if ( is_single ( [ 531, 141 ] ) ) {
unset( $graph_piece[‘datePublished’], $graph_piece[‘dateModified’] );
return $graph_piece;
}
}
add_filter( ‘wpseo_schema_article’, ‘vanv_remove_published_modified_dates’ );add_filter( ‘wpseo_schema_webpage’, ‘vanv_remove_published_modified_dates’ );
add_filter(
‘wpseo_frontend_presenter_classes’
, function($filter)
{
return array_diff($filter, [
‘Yoast\WP\SEO\Presenters\Open_Graph\Article_Published_Time_Presenter’,
‘Yoast\WP\SEO\Presenters\Open_Graph\Article_Modified_Time_Presenter’,
]);
}
);—————————————————————————————————
I am doing anything wrong? Can you please help?
Thank you.
- The topic ‘Hide from the Schema datePublished and dateModified only in certain posts’ is closed to new replies.