WordPress comment_time() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Template tag

Definition

In WordPress, comment_time() prints the time when a comment was posted.

By default it uses the time format from Settings → General. You can pass a PHP time format to change it.

Syntax

Call it with no format for the site format, or pass a PHP time format.

WordPress
comment_time();
comment_time( 'H:i' );
comment_time( 'g:i a', 15 );
CallWhat it does
comment_time()Prints the time in the site's time format.
comment_time( 'H:i' )Prints the time in 24-hour format.
comment_time( 'g:i a', 15 )Prints the time of comment 15.

Use comment_date() to print the date of the comment.

Full declaration
WordPress
comment_time( string $format = '', int|WP_Comment $comment_id = 0 ): void

Parameters

ParameterDescription
$formatOptional. A PHP time format. If empty, WordPress uses the time_format option.
$comment_idOptional. A comment ID or WP_Comment object. Default is the current comment. Added in WordPress 6.2.

Return Value

Return ValueDescription
voidNothing is returned. The function prints the time.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — Default time

Print the time in the site format.

WordPress
<span class="time"><?php comment_time(); ?></span>

How It Works

  1. No format is given.
  2. WordPress uses the time format from your settings.
  3. The time is printed as plain text.

Example 2 — Custom format

Print the time in 24-hour format.

WordPress
<span class="time"><?php comment_time( 'H:i' ); ?></span>

How It Works

  1. H is the hour in 24-hour format.
  2. i is the minutes.
  3. Use any PHP time format here.

Example 3 — Date and time

Print the date and the time together.

WordPress
<p><?php comment_date(); ?> at <?php comment_time(); ?></p>

How It Works

  1. comment_date() prints the date.
  2. comment_time() prints the time.
  3. The word at is your own text.

Frequently Asked Questions

It prints the time when the current comment was posted.
Pass a PHP time format, such as 'H:i', as the first argument.
From the Time Format setting in Settings, General.
Use get_comment_time().
Use comment_date().

Next: comment_type()

Print the type of the current comment: Comment, Trackback, or Pingback.

comment_type() tutorial →

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.

11 people found this page helpful