Archived topic
Old Date Shows On Google
9 replies · Started by Rahul on March 21, 2021
Maybe you know a few weeks ago I had made a ticket for date snippets and finally, it solved.
But now I saw, there are 2 different update dates. Real post update shows on the post, and on the search engine shows old date, not updated. You can check the post and “keyword” Is it possible to shows the real updated dates on google?
Hi there,
Ultimately, Google chooses which date to display. However, we can force their hand a bit by displaying only the updated date in the HTML: https://docs.generatepress.com/article/generate_post_date_show_updated_only/
That should fix the issue.
Let us know :)
Would you say, where can I put it? Is it the element hooks or other?
Hi there,
The code from Tom's link is a PHP snippet.
Here's how you add that kind of PHP code - https://docs.generatepress.com/article/adding-php/
You can then try to ask Google to recrawl your site so the changes would reflect sooner.
Thank you, but still I have 3 active snippest, which one should I have to remove?
function db_modified_time_stamp( $output, $time_string ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">/ Updated %2$s</time> ';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time> ' . $time_string;
}
// Check Updated is newer thant published
$updated_time = get_the_modified_time( 'U' );
$published_time = get_the_time( 'U' ) + 86400;
// If modified date exists then ouput both time strings with modified date
if ( $updated_time > $published_time ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished" style="display: none;">/Updated %2$s</time>
<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified" style="display:inline;">/ Updated %4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date( 'F j, Y' ) ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date( 'F j, Y' ) )
);
return sprintf( '<span class="posted-on">%s</span> ',
$time_string
);
}
add_filter( 'generate_post_date_output', db_modified_time_stamp, 20, 2);
---------------------------------------------------------------------------------
----------------------------------------------------------------------------------
add_filter( 'generate_post_author_output', function() {
return sprintf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<span class="author-name" itemprop="name">%3$s</span></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
esc_html( get_the_author() ),
get_avatar( get_the_author_meta( 'ID' ) )
)
);
} );
------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'author',
'date'
);
} );
Ah I see the issue here now:
Your code for displaying the date has issues. Both your posted date and updated date have "Updated" text in it. I can read it on your code. Let's fix that.
Replace this:
function db_modified_time_stamp( $output, $time_string ) {
$time_string = ‘<time class=”entry-date published” datetime=”%1$s” itemprop=”datePublished”>/ Updated %2$s</time> ‘;
if ( get_the_time( ‘U’ ) !== get_the_modified_time( ‘U’ ) ) {
$time_string = ‘<time class=”updated” datetime=”%3$s” itemprop=”dateModified”>%4$s</time> ‘ . $time_string;
}
// Check Updated is newer thant published
$updated_time = get_the_modified_time( ‘U’ );
$published_time = get_the_time( ‘U’ ) + 86400;
// If modified date exists then ouput both time strings with modified date
if ( $updated_time > $published_time ) {
$time_string = ‘<time class=”entry-date published” datetime=”%1$s” itemprop=”datePublished” style=”display: none;”>/Updated %2$s</time>
<time class=”entry-date updated-date” datetime=”%3$s” itemprop=”dateModified” style=”display:inline;”>/ Updated %4$s</time>’;
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( ‘c’ ) ),
esc_html( get_the_date( ‘F j, Y’ ) ),
esc_attr( get_the_modified_date( ‘c’ ) ),
esc_html( get_the_modified_date( ‘F j, Y’ ) )
);
return sprintf( ‘<span class=”posted-on”>%s</span> ‘,
$time_string
);
}
add_filter( ‘generate_post_date_output’, db_modified_time_stamp, 20, 2);
With this:
function db_modified_time_stamp( $output, $time_string ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Posted %2$s</time> ';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time> ' . $time_string;
}
// Check Updated is newer thant published
$updated_time = get_the_modified_time( 'U' );
$published_time = get_the_time( 'U' ) + 86400;
// If modified date exists then ouput both time strings with modified date
if ( $updated_time > $published_time ) {
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified" style="display:inline;">/ Updated %4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date( 'F j, Y' ) ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date( 'F j, Y' ) )
);
return sprintf( '<span class="posted-on">%s</span> ',
$time_string
);
}
add_filter( 'generate_post_date_output', db_modified_time_stamp, 20, 2);
This is so Google Crawler bots don't get confused with the dates and can only find the updated date if there is one.
Dear, Elvin would you specify which one is correct? Just send one file. And if I have to use this one that is mentioned by "Tom" https://docs.generatepress.com/article/generate_post_date_show_updated_only/
Dear, Elvin would you specify which one is correct? Just send one file. And if I have to use this one that is mentioned by “Tom” https://docs.generatepress.com/article/generate_post_date_show_updated_only/
You can remove this code snippet you're using:
function db_modified_time_stamp( $output, $time_string ) {
$time_string = ‘<time class=”entry-date published” datetime=”%1$s” itemprop=”datePublished”>/ Updated %2$s</time> ‘;
if ( get_the_time( ‘U’ ) !== get_the_modified_time( ‘U’ ) ) {
$time_string = ‘<time class=”updated” datetime=”%3$s” itemprop=”dateModified”>%4$s</time> ‘ . $time_string;
}
// Check Updated is newer thant published
$updated_time = get_the_modified_time( ‘U’ );
$published_time = get_the_time( ‘U’ ) + 86400;
// If modified date exists then ouput both time strings with modified date
if ( $updated_time > $published_time ) {
$time_string = ‘<time class=”entry-date published” datetime=”%1$s” itemprop=”datePublished” style=”display: none;”>/Updated %2$s</time>
<time class=”entry-date updated-date” datetime=”%3$s” itemprop=”dateModified” style=”display:inline;”>/ Updated %4$s</time>’;
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( ‘c’ ) ),
esc_html( get_the_date( ‘F j, Y’ ) ),
esc_attr( get_the_modified_date( ‘c’ ) ),
esc_html( get_the_modified_date( ‘F j, Y’ ) )
);
return sprintf( ‘<span class=”posted-on”>%s</span> ‘,
$time_string
);
}
add_filter( ‘generate_post_date_output’, db_modified_time_stamp, 20, 2);
And use the PHP snippet from Tom's link which is this one:
add_filter( 'generate_post_date_show_updated_only', '__return_true' );
Note: The effect of replacing your current PHP snippet with the one Tom shared is, the word "Updated" before the post date would be removed. But you should be able to add that back with this CSS:
time.entry-date:before {
content: "Updated ";
}
Thank you so much Mr. Elvin I have updated everything you told me. But you should check my site's all CSS about the updated date. Because previously I used a lot of CSS provided by the support team. If you found unnecessary files I will remove them.
Since the PHP code you've used had inline CSS. The CSS for that was removed too when you replaced the PHP snippet so you don't have to worry about unused CSS related to the dates. :)