The get_cancel_comment_reply_link() WordPress PHP function retrieves the HTML content for a cancel comment reply link.
Usage
get_cancel_comment_reply_link($text, $post);
Parameters
$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()
Examples
Default cancel reply link
This example displays the default cancel reply link.
echo get_cancel_comment_reply_link();
Custom cancel reply link text
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);
Display cancel reply link within a comment form
This example demonstrates how to display a cancel reply link within a comment form.
comment_form(array( 'cancel_reply_link' => get_cancel_comment_reply_link('Cancel your reply') ));
Using the cancel reply link with custom HTML
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>";