WordPress comment_type() Function

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

Definition

In WordPress, comment_type() prints the type of the current comment. The default texts are Comment, Trackback, and Pingback.

A normal comment is written by a visitor. A pingback or a trackback is a notice from another site that linked to your post.

Syntax

Call it with no text for the defaults, or pass your own text for each type.

WordPress
comment_type();
comment_type( 'Comment', 'Trackback', 'Pingback' );
CallWhat it does
comment_type()Prints the default label for the current comment.
comment_type( 'Reply', 'Link notice', 'Link notice' )Prints your own labels.
get_comment_type()Returns comment, pingback, or trackback.

Any type other than trackback or pingback prints the comment text.

Full declaration
WordPress
comment_type( string|false $comment_text = false, string|false $trackback_text = false, string|false $pingback_text = false ): void

Parameters

ParameterDescription
$comment_textOptional. Text for a normal comment. Default Comment.
$trackback_textOptional. Text for a trackback. Default Trackback.
$pingback_textOptional. Text for a pingback. Default Pingback.

Return Value

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

WordPress Examples

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

Example 1 — Default label

Print the type label.

WordPress
<p><?php comment_type(); ?> on <?php the_title(); ?></p>

How It Works

  1. The current comment is a normal comment.
  2. comment_type() prints the word Comment.
  3. the_title() prints the post title.

Example 2 — Custom labels

Use your own words for each type.

WordPress
<span class="type"><?php comment_type( 'Reply', 'Link notice', 'Link notice' ); ?></span>

How It Works

  1. The first text is for a normal comment.
  2. The second is for a trackback and the third for a pingback.
  3. This output is for a pingback.

Example 3 — Check the type

Use get_comment_type() to treat pingbacks in another way.

WordPress
<?php if ( 'pingback' === get_comment_type() ) : ?>
  <p class="ping">Another site linked to this post.</p>
<?php endif; ?>

How It Works

  1. get_comment_type() returns a lowercase type.
  2. The notice prints only for pingbacks.
  3. Normal comments skip this block.

Frequently Asked Questions

A label for the type of the current comment, such as Comment, Trackback, or Pingback.
A notice that WordPress sends when another site links to your post.
Yes. Pass your own text for each type.
Use get_comment_type(). It returns comment, pingback, or trackback.
Inside the comment loop, for example in a comment callback.

Next: comments_link()

Print the URL of the comments section of the current post.

comments_link() 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.

12 people found this page helpful