Using WordPress ‘get_cancel_comment_reply_link()’ PHP function

The get_cancel_comment_reply_link() WordPress PHP function retrieves the HTML content for a cancel comment reply link.


get_cancel_comment_reply_link($text, $post);


  • $text (string, optional) – Text to display for the cancel reply link. If empty, defaults to ‘Click here to cancel reply’. Default: ''
  • $post (int|WP_Post|null, optional) – The post the comment thread is being displayed for. Defaults to the current global post. Default: null

More information

See WordPress Developer Resources: get_cancel_comment_reply_link()


This example displays the default cancel reply link.

echo get_cancel_comment_reply_link();

This example displays a cancel reply link with custom text.

echo get_cancel_comment_reply_link('Cancel your reply');

Display cancel reply link for a specific post

This example displays a cancel reply link for a specific post.

$post_id = 42; // Replace with the ID of the desired post
echo get_cancel_comment_reply_link('Cancel your reply', $post_id);

This example demonstrates how to display a cancel reply link within a comment form.

    'cancel_reply_link' => get_cancel_comment_reply_link('Cancel your reply')

This example shows how to use the cancel reply link with custom HTML.

$cancel_link = get_cancel_comment_reply_link('Cancel your reply');
echo "<div class='cancel-reply'>{$cancel_link}</div>";