网站发布新文章后,通过邮件通知已注册的用户,可以增加用户的粘度。WordPress 站点要实现这个功能,只需要在当前主题的 functions.php 文件添加下面的代码即可:
/**
* WordPress 发布新文章后<a href="https://www.wpdaxue.com/tag/%e9%82%ae%e4%bb%b6%e9%80%9a%e7%9f%a5" title="查看与【邮件通知】相关的文章" target="_blank" rel="noopener">邮件通知</a>已注册的用户
* https://www.wpdaxue.com/new-post-email-users.html
*/
function wpdx_email_users($post_ID) {
global $wpdb;
$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
$users = implode(",", $usersarray);
mail($users, 'WordPress大学发布了新文章', 'WordPress大学更刚发布了新文章,请访问 https://www.wpdaxue.com 阅读。');
return $post_ID;
}
add_action('publish_post', 'wpdx_email_users'); |
/**
* WordPress 发布新文章后<a href="https://www.wpdaxue.com/tag/%e9%82%ae%e4%bb%b6%e9%80%9a%e7%9f%a5" title="查看与【邮件通知】相关的文章" target="_blank" rel="noopener">邮件通知</a>已注册的用户
* https://www.wpdaxue.com/new-post-email-users.html
*/
function wpdx_email_users($post_ID) {
global $wpdb;
$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
$users = implode(",", $usersarray);
mail($users, 'WordPress大学发布了新文章', 'WordPress大学更刚发布了新文章,请访问 https://www.wpdaxue.com 阅读。');
return $post_ID;
}
add_action('publish_post', 'wpdx_email_users');
你可以根据自己的实际,修改邮件的标题和内容。
如果你想不想折腾代码,可以使用 Notify Users E-Mail 插件,支持自定义接收邮件的用户类型、邮件主题和内容,也可以添加额外的收件人:

如果你还想给网站添加邮件订阅功能,可以使用 Simple Subscribe 插件,它不仅可同时支持给订阅用户和已注册用户发送邮件通知哦!
当然,只要发送邮件,就必须确保你的主机支持 mail 函数,或者使用 SMTP 功能。
来源:
https://www.wpdaxue.com/new-post-email-users.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33146.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57