Change recipient of email notifications for new comments in WordPress using comment_notification_recipients filter

Client’s website I was recently working on required the email notifications for new comments to be sent to the admin only and not the post author.

If you turn on the email notifications for new comments in WordPress, the post author will receive an email every time someone posts a comment on his or her post (‘Email me whenever Anyone posts a comment’ option).

New comment notifications and comment moderation options can be found in Settings > Discussion.

WordPress comments options- Email me whenever anyone posts a comment

You can find more details about the comment options in the WordPress Codex.

By default, whenever anyone posts a new comment, WordPress will notify the post author only.

However, a client’s website I was recently working on required the email notifications for new comments to be sent to the admin only and not the post author.

This can be achieved using the comment_notification_recipients filter.

comment_notification_recipients

The comment_notification_recipients filter allows you to filter the list of email addresses that will receive an email notification from WordPress about new comments. This enables you to not only add new email addresses that will be notified but also to remove or change them, depending on your requirements.

Sending new comment notifications to admin only

Below is a function that will send all new comment notifications to admin email address only, using the comment_notification_recipients filter.

function if_change_recipient_comment_notification( $emails, $comment_id ){
  $admin_email = get_bloginfo('admin_email');

  return array( $admin_email );
}
add_filter( 'comment_notification_recipients', 'if_change_recipient_comment_notification', 10, 2 );

In the above code, we are replacing the default array of email addresses passed to the function ($emails) with our own array. As we only want to send the new comment notifications to the admin, we only return the site’s admin email address. You can get the admin’s email using the WordPress get_bloginfo() function.

The above code could easily be changed to send the new comment notifications to any email address, including one that is not associated with the website. Below is a function that allows you to send new comment notifications to any email address.

 function if_change_recipient_comment_notification( $emails, $comment_id ){
 $recipient_email = 'example@example.com';
 
 return array( $recipient_email );
}
add_filter( 'comment_notification_recipients', 'if_change_recipient_comment_notification', 10, 2 ); 

 

Further reading

WordPress Codex: Settings, Discussion Screen

Why is there a smiley face at the bottom of my WordPress website?

Recently, while updating my website, I’ve noticed a tiny smiley face in the bottom left corner of my website. I do regular security checks and keep my website updated all the time, so I didn’t think someone has hacked it, but still, I was a little bit concerned as I didn’t know where it came from.

Here’s how it looks:

Smile face in the footer of WordPress website

What is the smiley face in the footer?

After a quick Google search, it turned out that the smiley face was being added by the Jetpack plugin. Why? According to Jetpack:

The image helps collect stats and makes the world a better place but should still work when hidden Smiley face 

However, Jeremy Herve, the Jetpack plugin contributor, says the image is no longer being used:
Smiley Image at bottom of site stats problem « WordPress.org Forums

So how do you hide the smiley face?

To do this, log into your WordPress back-end and go to the ‘Site Stats’ in the Jetpack menu.

WordPress Jetpack - remove smiley face from website footer

Click the ‘Configure’ link at the top of the page.

WordPress - smile face from Jetpack

Scroll down to the ‘Smiley’ option and just check the box that says ‘Hide the stats smiley face image.’

Jetpack - hide the smiley face

And that’s it. The smiley face is now hidden.

Additional links

Here are some links and more information about the smiley face in the footer of the website:

Redirect to custom user dashboard after logging in with OneAll WordPress plugin


/* Change redirect URL for OnaAll Social Login */
function if_login_registration_redirect_filter ($url, $user_data){
$student_name = get_the_author_meta( 'user_nicename', $user_data->id );
$redirection_url = get_site_url() . '/author/' . $student_name;
return $redirection_url;
}
add_filter('oa_social_login_filter_registration_redirect_url', 'if_login_registration_redirect_filter', 10, 2);
add_filter('oa_social_login_filter_login_redirect_url', 'if_login_registration_redirect_filter', 10, 2);