Are you looking for a way to display post meta data in your WordPress blog posts?
Meta data for your posts include information like the date they were published, the author’s name, categories and tags, and so on.
We’ll show you how to easily display post meta data in WordPress posts in this article.
What is WordPress Post Meta Data?
Meta data for a blog post is information about the post that isn’t included in the actual content. This includes details such as the date of the post, the author’s name, categories and tags, as well as custom taxonomies.
This information can be displayed in a variety of places depending on the WordPress theme you’re using. For instance, below the post title, after the content, in the sidebar, and so on.
This data aids your visitors in learning more about the content they’re looking at.
Your post meta data can improve the user experience, make your site look more professional, and even increase pageviews when used correctly.
Displaying too-much post meta data, on the other hand, can make your website appear cluttered and unprofessional.
You can add or remove post meta information to make your website more appealing and useful, depending on your needs.
Note that each WordPress theme handles post meta data in a unique way. Some themes include a built-in feature that allows you to customize your meta data without having to write any code.
Some themes, for example, edit meta data using the WordPress theme customizer, while others have their own theme options panel.
Before you go any further, check the documentation for your WordPress theme to see if you can edit theme meta data without using code.
So, let’s take a look at how to display and customize the meta data for your blog posts in WordPress.
How Are Post Meta Data Displayed in WordPress Themes?
You’ll need to add code to your WordPress files to display or change your post meta data. Check out our guide on how to copy and paste code in WordPress if you haven’t done so before.
Individual theme files can be modified directly, or a child theme can be created to override these files. You can directly add or modify the code in your existing theme files if you’re making your own custom theme.
WordPress themes can display post meta data in a variety of ways. Simple code can be found below the post title in some themes.
1
|
By <?php the_author_posts_link(); ?> on <?php the_time( 'F jS, Y' ); ?> in <?php the_category( ', ' ); ?> <?php edit_post_link(__( '{Edit}' ), '' ); ?> |
The author’s name, post date, and category or categories are all displayed in the code above.
To display post meta data, other themes can define their own template tags, functions, and classes. These functions are then invoked in the theme files that handle post display.
Post meta data code is usually found in the index.php, single.php, archive.php, and individual content templates of your theme.
Let’s look at some examples of how to display various post meta data in your WordPress blog now.
How to Show or Hide the Date of a Post in WordPress
To show the date a post was published, add the following code to your theme.
1
|
<p>This article was published on: <?php the_time( 'm/j/y g:i A' ) ?></p> |
The time and date your post was published are simply added with this code.
Take note of the characters used within the time function. These characters are known as format characters, and they instruct PHP on how to format the date and time.
This is how your visitors will see the post meta date.
If you want to remove the dates from your WordPress posts, look for the code in your theme files that uses the time or the date functions and delete those lines.
How to Make the Last Update Date of WordPress Posts Visible
If you frequently update old articles on your website, the last updated date of your posts may be displayed.
This keeps your content looking new and attracts readers who might not have read a post from years ago.
Simply include the following code in your theme files wherever you want the most recent update date to appear:
1
2
3
4
5
6
7
8
9
|
$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> " ; } |
This is how your readers will see the most recent update date.
In WordPress, how do I show or hide the author’s name?
You’ll need to add the following code to your theme files to display the author’s name.
1
|
<p>This article was written by <?php the_author(); ?></p> |
The author tag is used in this code, which only displays the author’s name.
You can also show the author’s name, which will take you to an author page with a list of all of that author’s posts.
As shown in the code below, simply replace the author tag with the author posts link:
1
|
<p>View all articles by <?php the_author_posts_link(); ?></p> |
Here’s how your readers will see the post meta data with only the author name.
If you want to remove the author’s name from your theme, look for and delete the author, and the author posts link tags in the theme files.
How to Make Categories Visible or Invisible in WordPress Posts
You’ll need to add the following code to your theme files to display your post categories:
1
|
<p>This post was filed under: <?php the_category( ', ' ) ?></p> |
The comma separates the post categories in this code. You can use any character as a separator between category names in place of the comma.
Here’s how your post meta data, which displays post categories to your readers, will appear.
If you want to remove category names from WordPress posts, look for the line in your theme files with the category tag and delete it.
Tags in WordPress Posts: How to Show or Hide Them
You’ll need to add the following code to your theme files to display post tags:
1
|
<p>Tags: <?php the_tags(); ?></p> |
All tags associated with the post will be displayed in this code, separated by a comma. Any character you want to use as a separator can be used in place of the comma.
The following code, for example, will display tags separated by a slash.
1
|
<?php the_tags( 'Tags: ' / ', ' , '<br />' ); ?> |
As you can see, the tag are a three-parameter function.
1
|
the_tags( $before , $separator , $after ) |
The before and after parameters can be used to add any text or HTML you want. This allows you to add CSS classes to tags in WordPress, which you can then use to style them.
Consider the following scenario:
1
|
<?php the_tags( '<div class="wpb-tags">Tags: ' , ' ' , '</div>' ); |
The following is an example of how your post meta tags will appear to your readers:
If you don’t want tags to appear before or after each post, find the line with the tags() code in your theme files and delete it.
There’s a lot more you can do with displaying post meta data if you’re a more advanced user.
Custom fields, for example, can be used to add your own meta data to WordPress posts. You can also make your own custom meta boxes to show the custom fields.
We hope you found this article useful in learning how to display blog post meta data in WordPress themes.