How to automatically notify members of your new posts

Your WordPress website is almost done. You still have a thing here and a thing there to tweak but you have already published your website and gathered numerous views and some registered members who really like your articles. Now you should take care of your loyal visitors and let them now when new content is published.

Wouldn’t it be great to ask WordPress for help and let the system automatically notify your members about new posts? In this article, we are about to show you how to do that.

Like with almost anything in WordPress, you can do the job by yourself or you can install a plugin.

First, we would like to show you the code which can do trick so you don’t have to install another plugin. Of course, a plugin will have more features, but if you need a simple email notification for your users, this code will do:

  1. Open your functions.php file
  2. Copy and paste the following code:
  3. function email_members($post_ID)  {
    global $wpdb;
    $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
    $users = implode(",", $usersarray);
    mail($users, "Hey, there’s a new post on my cool website", 'New post can be found at www.mydomain.com');
    return $post_ID;
    }
    add_action('publish_post', 'email_members');
  4. Save changes

After you copy and paste the code, don’t forget to personalize the message your members will get in mail and get your link right. After that, whenever you publish a new post, your WordPress will know what to do – and that’s to send mails to everyone in the users database.

Now the changes have been made, but keep in mind that most people won’t like getting an email every time you publish something. That basically means that you don’t want to notify members of your every post if you have ten posts per day. If you do have that number of posts, you should look out for another solution and maybe create newsletter or contact your members only about special content periodically.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *