Astra provides an option to display the published or last updated dates on the blog meta. You can control this from the customizer and choose to display either. You can check this doc to see how it works.
Sometimes, there is a requirement to display both published and last updated dates on the blog posts by providing a clear view of when the post was published and updated.
In this guide, we will walk you through the process of displaying both published and last updated dates on the blog posts, for both Blog Archive and Single Posts.
Display Published and Last Updated Dates on the Entire Blog
To implement both published and last updated dates on the entire blog including the blog/archive pages (i.e., main blog page, category, or tags) and single posts, you can add the following code to your website.
function your_prefix_post_date2( $output ) {
$format = apply_filters( 'astra_post_date_format', '' );
$modified_date = esc_html( get_the_modified_date( $format ) );
$modified_on = sprintf(
esc_html( '%s' ),
$modified_date
);
$updated_output = '';
$separator = ' /';
$separator = apply_filters( 'astra_post_meta_separator', $separator );
$published_string = __('Published : ' , 'astra');
$updated_string = __('' . $separator . ' Last updated : ' , 'astra' );
$updated_output .= '';
$updated_output .= ' ' . $modified_on . '';
$updated_output .= '';
$modified_output = $published_string . $output . $updated_string . $updated_output;
return $modified_output;
}
add_filter( 'astra_post_date', 'your_prefix_post_date2' );
The above code will display both published and last updated dates on the blog pages. By default, it works for both archive and single posts. You can modify it according to your requirements and add it to the functions.php file of the child theme.
If you don’t have your Child Theme installed, please check this article on how to do it. If you are not sure how to add this code, please check this article.
Display Published and Last Updated Dates on Single Posts or Blog/Archives
The above code, if added directly to the child theme, enables both published and last updated dates on both the blog/archive and the single posts.
But, if you wish to display it only on the single posts or only on the blog/archive pages, you can use the below approach:
1. First, enable the Site Builder module of Astra Pro
2. In the Site Builder, create a hook layout and switch to the code editor
3. In the code editor, add the above code within the PHP code syntax as instructed below:
<?php
// Add the code here
?>
4. Now, select the layout as Hooks and Action as WP_Head
5. Once the layout and actions are selected, it is time to apply the correct display conditions. The display conditions will allow you to display both the published and last updated dates on the blog/archive page or single posts.
To display the published and last updated dates only the single posts, select all posts.
After making the above changes, publish the layout and check the front.
Using the Site Builder module, you can also create a custom template for the single posts and modify the entire layout and content according to your requirements. You may check this doc to see how it works.
Now, when you see your blog posts, the post meta will include both the last updated and published dates as shown in the below screenshot:
To display it only on the blog/archive pages, simply change the display conditions in the Site Builder layout.
We hope this document has been helpful. If you have any questions, feel free to leave a comment below.