The comment_author_email_link() WordPress PHP function displays the HTML email link of the current comment’s author. It’s designed to help protect the email addresses of commenters from email harvesters.
Usage
To use the function, you simply call it in your template where you want the link to appear. Here’s an example where the link text is “Email the Author”, with a ‘>’ before and a ‘<‘ after the link:
comment_author_email_link('Email the Author', ' > ', ' < ');
Parameters
- $linktext (string) – Optional. This is the text that will be displayed instead of the comment author’s email address. Defaults to an empty string.
- $before (string) – Optional. This is the text or HTML that will be displayed before the email link. Defaults to an empty string.
- $after (string) – Optional. This is the text or HTML that will be displayed after the email link. Defaults to an empty string.
- $comment (int|WP_Comment) – Optional. This can be a comment ID or WP_Comment object. If not specified, the function will use the current comment.
More information
See WordPress Developer Resources: comment_author_email_link()
This function is part of the WordPress core and has not been depreciated as of the current version.
Examples
Basic Usage
Display the comment author’s email link as a text string.
comment_author_email_link();
Custom Text for Link
Display “Email the Author” instead of the raw email address.
comment_author_email_link('Email the Author');
Text Before and After Link
Add ‘>’ before and ‘<‘ after the email link.
comment_author_email_link('Email the Author', ' > ', ' < ');
Specifying a Comment
Display email link of a specific comment (comment ID 5 in this case).
comment_author_email_link('Email the Author', ' > ', ' < ', 5);
Using a WP_Comment Object
Display email link using a WP_Comment object.
// Assume $comment is a WP_Comment object comment_author_email_link('Email the Author', ' > ', ' < ', $comment);