How to Add Author Name to WordPress Posts and Pages

Jason Shaw | July 9th, 2020

This post is a quick technical reference for WordPress web developers.

Website developers are often asked to add certain metadata to WordPress blog posts. Most commonly, that metadata is the author’s name and the post’s publication date.

Most WordPress themes have some kind of templated approach for accomplishing this. Or, website owners choose to install plugins that make it easier to manage and add post metadata.

How to add author name to WordPress posts and pages

Sometimes, however, neither of these options are suitable (or appealing). Recently I created a way to incorporate the Author and Last Modified Date using a single shortcode.

Best of all, this can be done without installing a(nother) plugin!

How to get the Author name

Function: get_the_author()

The first step to adding the author name to a WordPress posts is to use this handy function. It will return the author’s name for the current post, or a given post_id that can be passed in as a function argument. The name is pulled from the list of authenticated website Users, where the user is the one who originally created the post.

How to get the Last Updated Date

Function: get_the_modified_date()

This function is pretty self-explanatory. For a given post_id, the most recent modified date is retrieved and returned in date format.

Date formatting in PHP

Using PHP, it’s easy to display date formats in many ways. Here are some examples which can be used in conjunction with the aforementioned get_the_modified_date() function.

// To show: 12:49:00 PM
echo date('h:i:s P');
// To show: Monday, 11:04:09 AM
echo date('l, h:i:s A');
// To show: 10 January 2020, 08:45:00 PM
echo date('d F Y, h:i:s P');

Final code

Once you have one of these functions in your theme’s functions.php file, simply add the corresponding shortcode into your WordPress blog post or page content.

Want to see this in action? Simply scroll to the top of this page.

photo
Author: Jason Shaw

With an Engineering degree and over 15 years of experience in web development, I’ve helped many businesses solve complex website and SEO issues. As the founder of Decodist (and small business owner) I can help you become more successful online.

Need To Fix Your Website?

I’d be happy to speak with you about your online business goals and create a tailored strategy.