Example 1 — Print the time
Print the publish time.
<p>Posted at <?php the_time(); ?></p> How It Works
- With no format, the time format from Settings > General is used.
the_time()prints the time of the post.- The text before is ours.

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.
A few ways to call the_time().
<p>Posted at <?php the_time( 'g:i a' ); ?></p> | Call | What 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.
the_time( string $format = '' ): void | Parameter | Description |
|---|---|
$format | string. A PHP date format. Default is the site time format. |
| Return Value | Description |
|---|---|
| void | Nothing is returned. The value is printed. |
Three short examples. Each one shows the code and what it prints.
Print the publish time.
<p>Posted at <?php the_time(); ?></p> the_time() prints the time of the post.Pass a date format to print a date.
<?php while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<p><?php the_time( 'F j, Y' ); ?></p>
<?php endwhile; ?> F j, Y gives a full date.the_date() would have hidden the second one.Print both together.
<?php the_time( 'F j, Y \a\t g:i a' ); ?> \a\t prints the word at.Open the functions index for simple guides with examples and FAQs.
12 people found this page helpful