WordPress the_time() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints time or date

Definition

In WordPress, the_time() prints the time the post was published. With a different format it can print the date too.

Unlike the_date(), it prints for every post, so it is safe to use in a loop.

Syntax

A few ways to call the_time().

WordPress
<p>Posted at <?php the_time( 'g:i a' ); ?></p>
CallWhat it does
the_time()Print the time in the site format.
the_time( 'g:i a' )Print the time in your own format.
the_time( 'F j, Y' )Print the date instead.
get_the_time()Return the time as a string.

It prints the value. Any PHP date format letters work, so it can show a time, a date, or both.

Full declaration
WordPress
the_time( string $format = '' ): void

Parameters

ParameterDescription
$formatstring. A PHP date format. Default is the site time format.

Return Value

Return ValueDescription
voidNothing is returned. The value is printed.

WordPress Examples

Three short examples. Each one shows the code and what it prints.

Example 1 — Print the time

Print the publish time.

WordPress
<p>Posted at <?php the_time(); ?></p>

How It Works

  1. With no format, the time format from Settings > General is used.
  2. the_time() prints the time of the post.
  3. The text before is ours.

Example 2 — Print a date with it

Pass a date format to print a date.

WordPress
<?php while ( have_posts() ) : the_post(); ?>
  <h2><?php the_title(); ?></h2>
  <p><?php the_time( 'F j, Y' ); ?></p>
<?php endwhile; ?>

How It Works

  1. The format F j, Y gives a full date.
  2. Every post shows its date, even on the same day.
  3. the_date() would have hidden the second one.

Example 3 — Date and time

Print both together.

WordPress
<?php the_time( 'F j, Y \a\t g:i a' ); ?>

How It Works

  1. A backslash before a letter prints that letter as text.
  2. \a\t prints the word at.
  3. The other letters are formatted as date and time.

Frequently Asked Questions

It prints the time of the current post. With another format it can print the date.
the_time() prints every time. the_date() prints only once for each day.
Pass a date format, for example the_time( 'F j, Y' ).
Use get_the_time().
Use the_modified_time().

Browse all post functions

Open the functions index for simple guides with examples and FAQs.

Post Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful