Archived topic
How to display Last Updated date on pages and posts
21 replies · Started by Amit on January 31, 2018
In many results from Google, it's visible that people are using Last modified date. I am also thinking of adding the same to my posts and pages as well. Pages as of now don't display any dates so I require a separate code for displaying on pages and separate code for posts to display last modified date like this
https://www.coffeemakersadvisor.com/best-keurig-coffee-maker-reviews/
https://coffeemakerpicks.com/.
One more thing, the front is also a page so don't want to display date on the front page.
You can tell your posts to display the updated date like this: https://generatepress.com/forums/topic/post-updated-date/#post-470725
You can add the date to pages like this:
add_action( 'generate_after_entry_header', 'tu_page_meta' );
function tu_page_meta() {
if ( is_singular( 'page' ) ) : ?>
<div class="entry-meta">
<?php generate_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif;
}
Into which file should I place this code?
And what if I want to display the Last updated date on pages only?
I used the code at https://generatepress.com/forums/topic/post-updated-date/#post-470725. It removed even the already appearing date.
Tom's code can be added like using one of the methods here: https://docs.generatepress.com/article/adding-php/
I did added the code to the child theme in functions.php. The code didn't worked but it removed the 'published date'.
Did you remove the code from the site? I'm seeing the published date still.
Let me know :)
Yes I removed as it didn't worked!
Now I added again for your check.
Ah, add this CSS:
.posted-on .updated {
display: inline;
}
As for pages, is this snippet added?: https://generatepress.com/forums/topic/how-to-display-last-updated-date-on-pages-and-posts/#post-485093
Yes, now it displays the date. One addon, I want to display 'Last Modified' before the date.
Also, where should I insert the above provided code for displaying date in pages.
Add this:
.posted-on .updated:before {
content: "Last Updated: ";
}
You should add the other code snippet the same as any other snippet: https://docs.generatepress.com/article/adding-php/
Works perfectly....thanks Tom for the quick support. One of my favorite theme so far....
You're very welcome! :)
Hey Tom, how can I avoid displaying date on home page?