How do I remove the date from the google search results of my posts?
Is this related to WordPress or is it theme-specific?
How do I remove the date from the google search results of my posts?
Is this related to WordPress or is it theme-specific?
Paste this code in functions.php
add_filter( 'wpseo_show_date_in_snippet_preview', false); //Returning false on this will prevent the date from showing up in the snippet preview.
Note: WordPress SEO api
I think I got it.
Navigate to SEO>Titles and Metas and remove %%date%% from Meta description template field.
Unfortunately the accepted answer is incorrect. (See 1.)
Below is the working answer I have found. (Sourced here 2.)
add_action('wpseo_dc_'.'DC.date.issued', '__return_false'); // Premium only
add_filter( 'wpseo_og_article_published_time', '__return_false' );
add_filter( 'wpseo_og_article_modified_time', '__return_false' );
add_filter( 'wpseo_og_og_updated_time', '__return_false' );
Try this, it will work
// Remove DatePublished
add_filter( 'wpseo_schema_graph_pieces', 'remove_datePublished_from_schema', 11, 2 );
add_filter( 'wpseo_schema_webpage', 'remove_datePublished_property_from_webpage', 11, 1 );
/**
* Removes the DatePublished graph pieces from the schema collector.
*
* @param array $pieces The current graph pieces.
* @param string $context The current context.
*
* @return array The remaining graph pieces.
*/
function remove_datePublished_from_schema( $pieces, $context ) {
return \array_filter( $pieces, function( $piece ) {
return ! $piece instanceof \Yoast\WP\SEO\Generators\Schema\datePublished;
} );
}
/**
* Removes the DatePublished property from the WebPage piece.
*
* @param array $data The WebPage's properties.
*
* @return array The modified WebPage properties.
*/
function remove_datePublished_property_from_webpage( $data ) {
if (array_key_exists('datePublished', $data)) {
unset($data['datePublished']);
}
return $data;
}