How to design post meta data in WordPress

Important: Back up all of the files in the app/themes/[your_theme] folder before editing any files. Syntax errors, even a minor typo, can cause your site to become unusable.

Post meta data is information about a post, such as the date and time the post was published and the post author. The default meta data displayed with each post depends on which WordPress theme the site is using but usually includes some combination of the date, author, and post categories or tags.

The dynamic information displayed in post meta data is generated by template tags, which are bits of PHP code that tell WordPress to display some information. For example, the template tag that displays the author of a post is the_author:

<?php the_author(); ?>

How and where the meta data is displayed also depends on the theme. Common locations are below the post, above the post, and in the sidebar. The WordPress theme used in the examples in this article is a simple theme called Stripes.

Adding or changing post meta data text

Just as the default meta data displayed with each post depends on which theme is used, the steps for changing meta data also rely on the theme. The files that need to be edited will be in the app/themes/[your_theme] folder. Post meta data is often found in index.php, post.php, and single-post.php, among others. In our example, the file containing the post meta data is called entry-meta.php.

Log into your WordPress Dashboard, go to Appearance > Editor and select entry-meta.php.

Edit meta data

The default entry-meta.php code in this theme includes two template tags: the_author_posts_link, which displays the author’s name with a link to a page showing all of the author’s posts, and the_time, which indicates the date the post was published.

Template tags

The post meta data created by this default is shown below:

One of the many ways to customize the meta data is to add or change text around the template tags. In this example, we’ve added some text and removed the separator character (|) between the author and the date.

The meta data in the published post now looks like this:

Changing where post meta data is displayed

You can move the meta data so that it’s displayed above or below the post or in a sidebar. In this example, we’re moving the meta data from above the post to below it. In the WordPress dashboard, go to Appearance > Editor and select entry.php. The default code looks like this:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header>
<?php if ( is_singular() ) { echo '<h1 class="entry-title">'; } else { echo '<h2 class="entry-title">'; } ?><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a><?php if ( is_singular() ) { echo '</h1>'; } else { echo '</h2>'; } ?> <?php edit_post_link(); ?>
<?php if ( !is_search() ) get_template_part( 'entry', 'meta' ); ?>
</header>
<?php get_template_part( 'entry', ( is_front_page() || is_home() || is_front_page() && is_home() || is_archive() || is_search() ? 'summary' : 'content' ) ); ?>
<?php if ( is_singular() ) get_template_part( 'entry-footer' ); ?>
</article>

Delete the line of code shown below. It is the last line of code in the <header> section.

<?php if ( !is_search() ) get_template_part( 'entry', 'meta' ); ?>

Add this line immediately above </article>.

<?php if ( is_singular() ) get_template_part( 'entry-meta' ); ?>

The code should now look like this:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header>
<?php if ( is_singular() ) { echo '<h1 class="entry-title">'; } else { echo '<h2 class="entry-title">'; } ?><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a><?php if ( is_singular() ) { echo '</h1>'; } else { echo '</h2>'; } ?> <?php edit_post_link(); ?>
</header>
<?php get_template_part( 'entry', ( is_front_page() || is_home() || is_front_page() && is_home() || is_archive() || is_search() ? 'summary' : 'content' ) ); ?>
<?php if ( is_singular() ) get_template_part( 'entry-footer' ); ?>
<?php if ( is_singular() ) get_template_part( 'entry-meta' ); ?>
</article>

Click Update File. The meta data in the published post is now displayed below the post and the categories links.

More information

For more information about post meta data and template tags, see the help documentation included with your WordPress theme and the following WordPress documentation topics:

If you need help with your HostPapa account, please open a support ticket from your dashboard.

Related Articles

Get online with our affordable web hosting

Get online with our affordable web hosting

Learn more now
HostPapa Mustache