I am looking to use the ‘the_modified_date’ function to display the date and time of a specific post has been modified. This information will appear in the header of our website on every single page.
How would I go about completing this?
I can use to get the title, and was hoping there would be a way just as easy to display that posts date and time.
Thank you for your help.
2 Answers
Place this code snippet put in function.php, this should give you what you need.
function my_theme_wp_title( $title, $sep ) {
global $post;
/* my other title cases */
//get post's modified date
$m_date = get_the_modified_date();
//concatenate the current title with the date string, using the separator to be more clear
$title .= $sep . " " . $m_date;
return $title;
}
add_filter( 'wp_title', 'my_theme_wp_title', 10, 2 );
Basically we add our custom function hooked to the wp_title filter, thus altering wp_title function, giving us the flexibility to add custom logic in the title display.
Cheers!