Site icon T4Tutorials.com

PHP code for wordpress to show Published Updated Date, Author Name picture

PHP code for wordpress to show “Published Date”, “Updated Date”, “Author Name” and “Author picture” for wordpress pages and post.

You can place this code anywhere inside your WordPress theme files where you want to display this information. For example you can insert it

  • single.php
  • content.php
  • sidebar.php
  • Insert with the help of any plugin like ad inserter plugin etc.
<?php
// Get the post ID
$post_id = get_the_ID();

// Get the post information
$post = get_post($post_id);

// Get the author information
$author_id = $post->post_author;
$author_name = get_the_author_meta('display_name', $author_id);
$author_avatar = get_avatar($author_id, 32); // You can adjust the avatar size as needed

// Get the post dates
$published_date = get_the_date('F j, Y', $post_id);
$updated_date = get_the_modified_date('F j, Y', $post_id);

// Display the information
echo '<p>Published Date: ' . $published_date . '</p>';
echo '<p>Last Updated: ' . $updated_date . '</p>';
echo '<p>Author: ' . $author_name . '</p>';
echo '<p>Author Avatar: ' . $author_avatar . '</p>';
?>

Output

Published Date: September 25, 2019

Last Updated: November 5, 2022

Author: Prof. Fazal Rehman Shamil

Author Avatar:

Exit mobile version