Archived topic
How to show updated posts with plugin
13 replies · Started by Swadhin on March 1, 2019
Hi Tom,
I am facing a serious issue where Google is not picking up "last updated" date and time and showing published ones. I tried various codes (one Brian from woorkup uses, and ones I was provided within the GP forum).
At last, I need to resort to an external plugin (so that some posts like coupons that are very critical on date for CTR in search) would not lose rankings (they are losing rankings now).
I want to use the plugin "Last Modified Info plugin" as mentioned in this post on authority hacker.
Please tell me how to integrate it on my site (link given in website URL section).
P.S. I have made customizations for including gravatar in post meta section and that's why I don't want to hurt its design.
Have you checked this documentation https://docs.generatepress.com/article/show-the-updated-post-date/ ?
Try this code:
https://gist.github.com/generatepress/ba6e3febda3b856b8c3ac29fd5054ce6
That second link that Ender provided should help.
However, it's ultimately up to Google whether they show the updated date or not - all we can do is display the necessary HTML/microdata.
Hi Tom & Ender, thank you for those snippets.
I think I have added that code.
Can you please show me a way to integrate that plugin to show correctly in the post meta data.
Thanks
As far as I can see, that plugin couldn't be necessary with that code snippet :)
Hi Tom,
I used that code and it now shows two lat updated dates. I have included site and URL in the site section.
Let me know if you need login details too.
Do you have another filter added that alters the post meta? If so, can you share it with me?
I also got two dates and I have tried the function twice (about two weeks ago and today). I only have the CSS for generatepress added to show last updated date and when I added the function, it showed double last updated dates. Removing the css removed both dates. http://prntscr.com/msbrga
Yes Tom,
I have this code for showing author gravatar, date and comment link in post meta.
add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
function tu_fancy_byline( $date ) {
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></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' ) )
)
);
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
echo '</span>';
}
echo $date;
}
Also, I do have this code to customize the author gravatar
add_filter( 'generate_post_author_output', 'tu_add_author_gravatar' );
function tu_add_author_gravatar() {
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s %5$s<a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>',
__( 'by','generatepress'),
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' ) )
)
);
}
Apart from that, I have the following CSS related to dates:
.posted-on .updated {
display: inline-block;
}
.posted-on .updated + .entry-date {
display: none;
Thank you.
So this would be your full (and only) function:
add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
function tu_fancy_byline( $date ) {
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></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' ) )
)
);
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
echo '</span>';
}
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%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 = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
return sprintf( '<span class="posted-on">%s</span>', // WPCS: XSS ok, sanitization ok.
$time_string
);
}
Thanks Tom,
I applied it and it worked wonders!
Thanks so much again... I am really relieved.
I want to display gravatar image, name, no. of comments and last modified date below post title.
Please share code and also tell me where to add those codes.
Waiting for your feedback.
Sumit - i have answered this on your Topic.
Glad I could help! :)