i just display my recent published and modified posts in homepage (index.php). how can i display last modified date of my home page?


You can use the_modified_time( $format ) in the loop, where $format is the PHP date/time format. If left empty it'll show in the format from your site settings.

|improve this answer|||||

Some quick possibe solutions working in templates:

If you have a page template for the homepage you can output somewhere

<?php echo "Last modified on: ".$post->post_modified; ?>

If you work on index.php of your theme

<?php if ( is_home() || is_front_page()){echo "Last modified on: ".$post->post_modified;}?>

The first example above can be used also in single.php or page.php and will show the last modified date of the current post/page you're viewing. The second will be visible only in homepage. To show this anywere else you can create a shortcode: https://codex.wordpress.org/Shortcode_API

function post_date_modified_shortcode($atts, $content = null) {
  //echo  "Last modified on: ".$_post->post_modified;
  $datetime = new DateTime($_post->post_modified);
  echo  "Last modified on: ".$datetime->format('c'); //Returns ISO8601 in proper format
  return ob_get_clean();        

add_shortcode("POST_MODIFIED", "post_date_modified_shortcode");

Then in the content editor where you want to output the last modified date ( note that you can pass the ID of the post/page you want to ge this information ) you can use:

[POST_MODIFIED post=371]

being 371 the post ID of your homepage ( or any other post/page ) this will output something like:

Last modified on: 2020-01-13 15:49:51

Of course there're many more possible solutions

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.