The cancel_comment_reply_link() WordPress PHP function displays HTML content for a cancel comment reply link.
Usage
This function can be used to display a custom message for the cancel reply link in the comments section. If no text is provided, it defaults to ‘Click here to cancel reply’.
cancel_comment_reply_link('Custom Cancel Message');
Parameters
- $text (string, optional): Text to display for cancel reply link. If empty, defaults to ‘Click here to cancel reply’. Default is an empty string.
More information
See WordPress Developer Resources: cancel_comment_reply_link()
Examples
Display Default Message
If you don’t provide any text, the function will display the default message ‘Click here to cancel reply’.
cancel_comment_reply_link();
Display Custom Message
You can display a custom message by passing it as a parameter.
cancel_comment_reply_link('Stop the Reply!');
Use with Translation Function
If you are building a site in multiple languages, you can use the translation function to display the message in the user’s language.
cancel_comment_reply_link( __( 'Cancel Reply', 'textdomain' ) );
Display Message with HTML Tags
You can also use HTML tags in your message.
cancel_comment_reply_link('<strong>Do Not Reply</strong>');
Use Variable as Message
You can use a variable as your custom message. This allows you to change the message dynamically.
$message = 'Back Out Now'; cancel_comment_reply_link($message);