If you add the following to the functions.php file of your child theme, you can modify the author’s email using the following instructions:
Example 1: Simple Email Modification
In this example, we’ll add a filter that modifies the email address of the comment author to a fixed value:
function wpdocs_custom_author_email( $comment_author_email, $comment_id ) {
// Modify the email address
return 'customemail@example.com';
}
add_filter( 'author_email', 'wpdocs_custom_author_email', 10, 2 );
Example 2: Conditionally Modifying the Email Address
In this example, we’ll modify the email address based on the comment ID:
function wpdocs_conditional_author_email( $comment_author_email, $comment_id ) {
if ( 123 === $comment_id ) {
// Modify the email address for comment ID 123
return 'specialemail@example.com';
}
// Return the original email address for other comments
return $comment_author_email;
}
add_filter( 'author_email', 'wpdocs_conditional_author_email', 10, 2 );
Example 3: Another Conditionally Modifying the Email Address:
Change the email based on certain conditions, such as the comment author’s role.
function wpdocs_conditional_comment_author_email( $comment_author_email, $comment_id ) {
$comment = get_comment( $comment_id );
// Check if the author is an admin
if ( user_can( $comment->user_id, 'administrator' ) ) {
return 'admin@example.com';
}
return $comment_author_email;
}
add_filter( 'author_email', 'wpdocs_conditional_comment_author_email', 10, 2 );
The author_email filter in WordPress provides a flexible way to modify comment author email addresses. By creating callback functions and hooking them into the filter, you can customize how these email addresses are handled on your website. Whether it’s for privacy, conditional changes, or logging purposes, the author_email filter can be utilized in various ways to meet your needs.
You must log in before being able to contribute a note or feedback.
If you add the following to the functions.php file of your child theme, you can modify the author’s email using the following instructions:
Example 1: Simple Email Modification
In this example, we’ll add a filter that modifies the email address of the comment author to a fixed value:
Example 2: Conditionally Modifying the Email Address
In this example, we’ll modify the email address based on the comment ID:
Example 3: Another Conditionally Modifying the Email Address:
Change the email based on certain conditions, such as the comment author’s role.
The
author_email
filter in WordPress provides a flexible way to modify comment author email addresses. By creating callback functions and hooking them into the filter, you can customize how these email addresses are handled on your website. Whether it’s for privacy, conditional changes, or logging purposes, theauthor_email
filter can be utilized in various ways to meet your needs.