How to show author image, name and last modified date with pages in wordpress.
Put this code in functions.php file and enjoy.
function add_updated_date_author_after_title($title, $id) {
// Check if it's a single post or page
if (is_singular() && in_the_loop() && is_main_query()) {
// Get the last modified time
$modified_date = get_the_modified_time('F j, Y', $id);
// Get the author's name
$author_name = get_the_author();
// Get the author's avatar (size 50px)
$author_avatar = get_avatar(get_the_author_meta('ID'), 50);
// Check if the post is updated (modified date is different from the published date)
if (get_the_modified_time() !== get_the_time()) {
// Append the author's avatar, name, and last updated date after the title
$title .= '<div class="author-info">';
$title .= '<div class="author-avatar">' . $author_avatar . '</div>';
$title .= '<p class="last-updated-author">By: ' . $author_name . ' | Last updated: ' . $modified_date . '</p>';
$title .= '</div>';
}
}
return $title;
}
add_filter('the_title', 'add_updated_date_author_after_title', 10, 2);