Getting the latest message in Wordpress

I want to dynamically display Last Date Date and time in a title in Wordpress. Please help me with the code that I can get the last published time and date from the WP database and get it on my Header.php or Somewhere else (HTML). Thank.

+4
source share
2 answers

This code can be used to get the latest date and time message in header.php

<?php echo get_lastpostdate(); ?>

Here is the function link https://codex.wordpress.org/Function_Reference/get_lastpostdate

+4
source

You can use wp_get_recent_posts()to get the last message:

$recent_posts = wp_get_recent_posts( array( 'numberposts' => '1' ) );
echo $recent_posts[0]['post_date'];
0
source

Source: https://habr.com/ru/post/1663890/


All Articles