How to Display and Customize Post Dates in GeneratePress
Content
One of the most common questions from GeneratePress users is how to manage post dates on their website. Many site owners want to display both the original publication date and the last modified date, or even replace the published date entirely with the updated date. This is crucial for content that is regularly revised, as it shows visitors the information is current.
Why This Happens
By default, WordPress and the GeneratePress theme display the publication date. The theme's structure includes the HTML for a modified date, but it is often hidden by default with CSS, which can lead to a brief flash of both dates (a layout shift) when using certain caching or critical CSS plugins.
Common Solutions
1. Displaying the Last Updated Date with CSS
If your theme is already outputting the modified date but it's hidden, you can use custom CSS to display it. Add the following code to your Customizer's Additional CSS panel:
.posted-on .updated {
display: inline-block !important;
}
.posted-on .updated:before {
content: "Last Updated on ";
}
.posted-on .entry-date:before {
content: "Published on ";
}
2. Using a Custom Function (Advanced)
For more control, you can use a code snippet in your child theme's functions.php file. This approach modifies the HTML output for the dates. Note: Always use a child theme to avoid losing changes after theme updates.
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
$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="entry-date updated-date" datetime="%3$s" itemprop="dateModified">%4$s</time>' . $time_string;
}
$output = 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 $output;
}, 10, 2 );
3. Hiding the Modified Date to Prevent Layout Shift (CLS)
If you are experiencing a Cumulative Layout Shift (CLS) because a caching plugin briefly shows both dates, you can permanently hide the modified date with this CSS:
time.updated {
display: none !important;
}
Important Considerations
- Premium Features: Some advanced date customization options, like changing the text "Updated on" or using the Elements module for specific layouts, are part of the GeneratePress Premium plugin. According to WordPress.org forum rules, support for premium features cannot be provided in the free forums. For help with these, you would need to contact the GeneratePress team through their official premium support forum.
- Custom Fields: For displaying specialized dates like a "medically reviewed on" date, you will need to create a custom field using a plugin like Advanced Custom Fields (ACF) and then write custom code to display that data in your template.
By understanding these methods, you can effectively control how dates are displayed on your GeneratePress site, ensuring a better experience for your readers and improved Core Web Vitals scores.
Related Support Threads Support
-
Need help with medically review datehttps://wordpress.org/support/topic/need-help-with-medically-review-date/
-
show a specific element by specific URL urlhttps://wordpress.org/support/topic/show-a-specific-element-by-specific-url-url/
-
Order articles by modification date on article lists like Blog pagehttps://wordpress.org/support/topic/order-articles-by-modification-date-on-article-lists-like-blog-page/
-
Theme or template namehttps://wordpress.org/support/topic/theme-or-template-name/
-
Change text “Updated on”https://wordpress.org/support/topic/change-text-updated-on/
-
How to add Custom CSS For yoast FAQ sectionhttps://wordpress.org/support/topic/how-to-add-custom-css-for-yoast-faq-section-2/
-
search bar dropping to new line, make it dynamichttps://wordpress.org/support/topic/search-bar-dropping-to-new-line-make-it-dynamic/
-
How to style the theme to example from site libraryhttps://wordpress.org/support/topic/how-to-style-the-theme-to-example-from-site-library/
-
How to change search box layouthttps://wordpress.org/support/topic/how-to-change-search-box-layout/
-
Show the “Last Updated on” Post Datehttps://wordpress.org/support/topic/show-the-last-updated-on-post-date/
-
i want css code for heading customizationhttps://wordpress.org/support/topic/i-want-css-code-for-heading-customization/
-
How to show last updated date in all posts instead of published datehttps://wordpress.org/support/topic/how-to-show-last-updated-date-in-all-posts-instead-of-published-date/
-
How to order posts according to creation datehttps://wordpress.org/support/topic/how-to-order-posts-according-to-creation-date/
-
How to change the name of categories in Newsroom template?https://wordpress.org/support/topic/how-to-change-the-name-of-categories-in-newsroom-template/
-
Can I modify the code based on this theme and use it as my own theme?https://wordpress.org/support/topic/can-i-modify-the-code-based-on-this-theme-and-use-it-as-my-own-theme/
-
How Can I create latest posts list as card viewhttps://wordpress.org/support/topic/how-can-i-create-latest-posts-list-as-card-view/
-
Double date printhttps://wordpress.org/support/topic/double-date-print/
-
Change the appearance of the comments columnhttps://wordpress.org/support/topic/change-the-appearance-of-the-comments-column/
-
Theme login section witg theme designhttps://wordpress.org/support/topic/theme-login-section-witg-theme-design/
-
Page creationhttps://wordpress.org/support/topic/page-creation-5/
-
Need help in making table of contentshttps://wordpress.org/support/topic/need-help-in-making-table-of-contents/
-
Customise latest recipes of “Chef” themehttps://wordpress.org/support/topic/customise-latest-recipes-of-chef-theme/
-
Need help with post datehttps://wordpress.org/support/topic/need-help-with-post-date/
-
customize search resulthttps://wordpress.org/support/topic/customize-search-result-3/
-
How can i add also the last update date no only the published datehttps://wordpress.org/support/topic/how-can-i-add-also-the-last-update-date-no-only-the-published-date/
-
Archive template designhttps://wordpress.org/support/topic/archive-template-design/
-
How to show announcement on all pages?https://wordpress.org/support/topic/how-to-show-announcement-on-all-pages/
-
previous and next buttons on individual blog posthttps://wordpress.org/support/topic/previous-and-next-buttons-on-individual-blog-post/
-
Need help for my website headerhttps://wordpress.org/support/topic/need-help-for-my-website-header/
-
mantain de same slughttps://wordpress.org/support/topic/mantain-de-same-slug/
-
Want to make table of contenthttps://wordpress.org/support/topic/want-to-make-table-of-content/
-
Customizing headerhttps://wordpress.org/support/topic/customizing-header-2/
-
i want to add custom cursor on my sitehttps://wordpress.org/support/topic/i-want-to-add-custom-cursor-on-my-site/
-
how can I show (time) ago post created?https://wordpress.org/support/topic/how-can-i-show-time-ago-post-created/
-
I want to make amazon product style like this sitehttps://wordpress.org/support/topic/i-want-to-make-amazon-product-style-like-this-site/
-
Question about “News Feed”.https://wordpress.org/support/topic/question-about-news-feed/
-
Page customizationhttps://wordpress.org/support/topic/page-customization-5/