I found my own solution!
Thanks @bcworkz. As I’m not a backend developer, this explanation sounds complicated to me.
But some minutes ago, my brain lightened an idea to solve this issue. This is the way that worked for me, step by step:
- Install the plugin Shortcodes Ultimate (which I use for a lot of things).
- Note: I’m using “Disable Gutenberg” plugin and using the classic editor (Gutenberg blocks are a horror nightmare).
- In our theme (preferably a child theme) we need to create a new folder and file that I will name “lastupdate-loop.php” here: /wp-content/themes/OURTHEME/templates/lastupdate-loop.php
- This file would be used by Shortcodes Ultimate. Edit that new file and paste the following code:
<?php defined( 'ABSPATH' ) || exit; if ( $posts->have_posts() ) : while ( $posts->have_posts() ) : $posts->the_post(); ?>
<?php echo get_post_modified_time('G:i T, l j F Y'); ?>
<?php endwhile; else : ?>
<p class="su-posts-not-found"><?php esc_html_e( 'Posts not found', 'shortcodes-ultimate' ); ?></p>
<?php endif; ?>
- In any widget or post/page (I’m showing this info using a widget in a dynamic sidebar), paste the following shortcode:
Last update time: [su_posts template="templates/lastupdate-loop.php" posts_per_page="1" post_type="post,page" order="desc" orderby="modified" post_status="any"]
What this shortcode exactly does?
This shortcode is showing the content for all the post and pages (post_type=”post,page”), with any post status (draft or published), and I’m calling only one item (posts_per_page=”1″), sort by modified date (order=”desc” orderby=”modified”).
It would return the last post or page I modified and, as you can see in the template I made, I’m showing only the_modified_time, which is the only data I need.
In the template code I used the following date format:
<?php echo get_post_modified_time('G:i T, l j F Y'); ?>
To show the date in the format you want, read Customize date and time format.
Complicated… And tricky!
I know.
But, as I’m not a backend, I really needed to find a shortcode solution that helps me to tell the users when whas the last time I made some changes in the website.
Cheers!