Archived topic
How to show the “Last Updated” Post date when using page header edit element
5 replies · Started by Mayor on January 27, 2020
Please, i need help on how to show the last updated post date, and also on reducing the font size for the Author Name and Date?
Thanks
Hi there,
- This should help:
https://docs.generatepress.com/article/show-the-updated-post-date/#show-the-%E2%80%9Cupdated%E2%80%9D-post-date-in-header-element
- Are you going to add the author name and date in the header element?
Let me know :)
Yes, this is the code I placed in the header element.
` <h1>{{post_title}}</h1>
Written by {{post_author}} on {{post_date}}
But i don't know how to add this code to the above, Please, how can i do it?
function post_modified_date() {
return get_the_modified_date();
}
add_shortcode( 'modified_date', 'post_modified_date' );
Try this for your HTML:
<h1>{{post_title}}</h1>
<div class="hero-meta">Written by {{post_author}} on {{post_date}}</div>
Then add this CSS:
.hero-meta {
font-size: 10px;
}
Adding CSS: https://docs.generatepress.com/article/adding-css/
The code to create shortcode needs to be added with one of these methods:
https://docs.generatepress.com/article/adding-php/
Let me know :)
The code you provided works perfectly. But it is not showing the date a post is updated. Something like, when I update a particular post, it should show that the post was updated
Hi there,
Did you add the add_shortcode function to your site?
If so remove it and add this instead:
function display_modified_date_shortcode () {
$mod_date = get_the_modified_date();
if ( get_the_date() !== $mod_date ) {
return 'Last Updated: ' . $mod_date;
}
}
add_shortcode( 'modified_date', 'display_modified_date_shortcode' );
https://docs.generatepress.com/article/adding-php/
Then add [modified_date] to your Header Element.
If the Post has been updated ( there has to be a days difference between published and modified ) it will also display the Last updated date