Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Display Blog Post Meta Data in Your WordPress Themes

Do you want to learn how to display post meta data in WordPress blog posts?

Post meta data includes information about your posts like the publication date, the author’s name, categories and tags, and more.

In this article, we’ll show you how to display post meta data in WordPress posts easily.

How to display post meta data in WordPress themes

What is Post Meta Data in WordPress?

Blog post meta data is information about a post that’s not part of the actual content. This includes information like the post date, author name, categories and tags, or custom taxonomies.

Post meta data example

Depending on the WordPress theme you are using, this information can be displayed in different locations. For example, below the post title, after your content, in your sidebar, and more.

This information helps your visitors learn more about the content they’re viewing.

When used the right way, your post meta data can improve the user experience, make your site look more professional, and even increase pageviews.

On the other hand, displaying too much post meta data can make your website look messy and unprofessional.

Post meta data messy example

Depending on your website, you can add or remove post meta information to make it more attractive and useful.

Note: All WordPress themes handle post meta data differently. Some themes have the built-in option to customize your meta data without writing any code.

For example, some themes use the WordPress theme customizer to edit the meta data, while others will have their own theme options panel.

Theme customizer meta data example

Before you move forward, make sure to check your WordPress theme documentation to see if you can edit theme meta data without code.

That being said, let’s show you how to display and customize your blog post meta data in WordPress.

How Do WordPress Themes Display Post Meta Data?

To display or change your post meta data you’ll need to add code to your WordPress files. If you haven’t done this before, then check out our guide on how to copy and paste code in WordPress.

You can modify the individual theme files directly, or create a child theme to override these theme files. If you are creating your own custom theme, then you can directly add or modify the code in your existing theme files.

There are multiple ways WordPress themes will display post meta data. Some themes will have simple code that’s located below the post title.

By <?php the_author_posts_link(); ?> on <?php the_time('F jS, Y'); ?>  in <?php the_category(', '); ?> <?php edit_post_link(__('{Edit}'), ''); ?>

The code above simply displays the author’s name, post date, and category or categories.

Other themes may define their own template tags, functions, and classes to display post meta data. These functions are then called in the theme files responsible for displaying posts.

Usually, you will find post meta data code in your theme’s index.php, single.php, archive.php, and individual content templates.

Now, let’s take a look at some examples of how to display different post meta data in your WordPress blog.

How to Display or Hide Post Date in WordPress

To display the publish date of a post, you need to add the following code to your theme.

<p>This article was published on: <?php the_time('m/j/y g:i A') ?></p>

This code simply adds the time and date your post was published.

Notice the characters inside the_time function. These are called format characters, and they tell PHP how to format the date and time.

Here’s how the post meta date will display to your visitors.

Post meta date

If you want to remove the dates from your WordPress posts, then you need to locate the code with the_time or the_date functions in your theme files and delete those lines.

How to Display Last Update Date for WordPress Posts

If you frequently update old articles on your website, then you may want to display the last updated date of your posts.

This helps your content look fresh and attract readers who may not read a post that was published years ago.

Simply add the following code to your theme files where you want to display the last updated date:

$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
echo "<p>Last modified on "; 
the_modified_time('F jS, Y'); 
echo " at "; 
the_modified_time(); 
echo "</p> "; 
} 

Here is how the last updated date will look to your readers.

Post meta modified date

For alternate methods and more detailed instructions, see our guide on how to display the last update date of your posts in WordPress.

How to Show or Hide Author Name in WordPress

To display the author name, you need to add the following code to your theme files.

<p>This article was written by <?php the_author(); ?></p>

This code uses the_author tag, which only displays the author name.

You can also display the author name that links to an author page that will list all of the posts written by that author.

Simply replace the_author tag with the the_author_posts_link, as shown in the code below:

<p>View all articles by <?php the_author_posts_link(); ?></p>

Here’s how the post meta data with only the author name will look to your readers.

Post meta author name

If you want to remove the author’s name from your theme, then you will need to locate the the_author or the_author_posts_link tags in your theme files and delete them.

How to Show or Hide Categories in WordPress Posts

To display your post categories, you need to add the following code to your theme files:

<p>This post was filed under: <?php the_category(', ') ?></p>

This code will display post categories separated by a comma. You can replace the comma with any character you want to use as a separator between category names.

Here’s how your post meta data showing post categories will look to your readers.

Post meta categories

If you want to remove category names from WordPress posts, then you need to locate the line with the_category tag in your theme files and delete it.

How to Show or Hide Tags in WordPress Posts

To display post tags, you need to add the following code to your theme files:

<p>Tags: <?php the_tags(); ?></p>

This code will simply show all tags associated with the post separated by a comma. You can replace the comma with any character you want to use as a separator.

For example, the following code will show tags separated by a slash.

 <?php the_tags( 'Tags: '/ ', ', '<br />' ); ?>

As you can see, the_tags function accepts three parameters.

the_tags($before, $separator, $after)

You can use the before and after parameters to add any text or HTML you want to add. This allows you to add CSS classes, which you can later use to style tags in WordPress.

Take a look at the following example:

<?php the_tags('<div class="wpb-tags">Tags: ', '  ', '</div>');

Here’s how your post meta tags will display to your readers:

Post meta display tags

If you don’t want to display tags before or after each post, then locate the line with the_tags() code and delete it from your theme files.

If you’re a more advanced user, then there’s a lot more you can do with displaying post meta data.

For example, you can use custom fields to add your own meta data to WordPress posts. Or, you can even create custom meta boxes to display the custom fields.

We hope this article helped you learn how to display blog post meta data in your WordPress themes. You may also want to see our guide on how much it costs to build a WordPress website and our comparison of the best email marketing services for small businesses.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

14 CommentsLeave a Reply

  1. I’m using code snippets and none of it work. I get the following error message “syntax error, unexpected ‘<', expecting end of file"

    • You may want to try adding above the code snippet you are trying to use the closing tag:
      ?>

      Admin

  2. Hey, great article. I want to display only one category on my blog. Let’s say if I have a post that comes under three categories, I want to display only one category out of three as metadata on a single post. How can I achieve it?

    • In those cases, it would normally be better to restructure your categories so the post would only be in one and use tags for organization

      Admin

  3. Thanks a lot for this article! I have one question. Is it possible to hide Tags: and This post was filed under: in case no tags or categories are set?

    • It would depend on how your specific theme has added it and you would normally add a conditional statement. If you check with the support for your theme they may be able to assist.

      Admin

  4. Hello,
    Wpbeginners helped me alot during my whole career. Thank You for all. I have a question that is there any role of published date and authors name in SEO? can it effect ranking ? I have a php website and I have published many posts but it doesn’t contain any author name or date. should I add these to my site ?

  5. Thanks for the info! So I’m trying to add a date to my posts. I saw your code but where is that added?

    Thank you!

    • It would depend on where you want to have the information displayed for where to add the code. If you reach out to the support for your current theme they should be able to point you to the right direction

      Admin

  6. Hello, i have news aggregator site how to add on homepage after every post source name and time when is published post (example google | before 45 minutes

  7. Hello, I have added an author name using the code provided in the article, but the link goes to the home page and not to the all articles written by this author. Please advise, thank you in advance, Liudmyla

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.