WordPress cancel_comment_reply_link() Function

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

Definition

In WordPress, cancel_comment_reply_link() prints the Cancel reply link. Visitors click it to stop replying to one comment and go back to the normal comment form.

It prints the link. It is used with threaded (nested) comments, next to the form title. If you use comment_form(), WordPress already adds this link for you.

Syntax

Call it with no text for the default label, or pass your own text.

WordPress
cancel_comment_reply_link();
cancel_comment_reply_link( 'Cancel reply' );
CallWhat it does
cancel_comment_reply_link()Prints the link with the default text.
cancel_comment_reply_link( 'Cancel' )Prints the link with your own text.
get_cancel_comment_reply_link()Returns the link as a string instead of printing it.

The link is hidden until a visitor clicks a Reply link. The comment-reply script must be loaded for this to work.

Full declaration
WordPress
cancel_comment_reply_link( string $link_text = '' ): void

Parameters

ParameterDescription
$link_textOptional. The text of the link. If empty, WordPress uses Click here to cancel reply.

Return Value

Return ValueDescription
voidNothing is returned. The function prints one a tag.

WordPress Examples

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

Example 1 — Default link

Print the cancel link with the default text.

WordPress
<p class="cancel-wrap"><?php cancel_comment_reply_link(); ?></p>

How It Works

  1. WordPress builds one link with the id cancel-comment-reply-link.
  2. The link has display:none until the visitor clicks Reply.
  3. The link points to the comment form (#respond).

Example 2 — Custom text

Use a short label of your own.

WordPress
<?php cancel_comment_reply_link( 'Cancel' ); ?>

How It Works

  1. The first argument is the link text.
  2. Only the text changes. The id and the link stay the same.
  3. Wrap the text in __() if your theme is translated.

Example 3 — Next to the form title

Show the form title and the cancel link together.

WordPress
<h3 id="reply-title">
  <?php comment_form_title( 'Leave a comment', 'Reply to %s' ); ?>
  <small><?php cancel_comment_reply_link( 'Cancel reply' ); ?></small>
</h3>

How It Works

  1. comment_form_title() prints the heading text.
  2. cancel_comment_reply_link() sits inside small next to it.
  3. This is the classic layout of an older comments.php file.

Frequently Asked Questions

It prints a link that lets a visitor cancel a reply and return to the main comment form.
It is hidden by default. It shows only after a visitor clicks a Reply link and the comment-reply script runs.
No. comment_form() already prints the cancel link in its title area.
Use get_cancel_comment_reply_link(). It returns the same HTML instead of printing it.
Add wp_enqueue_script( 'comment-reply' ) in your theme when threaded comments are on and the post is single.

Next: comment_author()

Print the name of the person who wrote the current comment.

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

8 people found this page helpful