How to Automatically notify users on new post

Do you ever wish to send your registered user’s an email whenever you do a new post , well this is basically very useful if you have a big list of user registered on your WordPress blog

So now lets implement this hacks go to functions.php and add the below code

function email_members($post_ID)  {
    global $wpdb;
    $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
    $users = implode(",", $usersarray);
    mail($users, "New Post on WordPress Den", 'A new post have been published on');
    return $post_ID;

add_action('publish_post', 'email_members');

Just edit the above code at line 5 to what ever you want

Subscribe to WPDEN


  • Cebu Tech Blogger

    Hi, how about if you just want to notify specific users on a new post? Is it possible with the code above?

    • Ritesh Sanap

      No the above code only sends mails to all the users

  • mirditori

    Adding to this conversation another plugin i found is this

    Can you tell me a bit more about that ?


    • Ritesh Sanap

      the details regarding this plugin can be found on its descriptions page, the plugin shows live notification of the new posts unlike sending email, you can think of the plugin like showing facebook updates.

  • Bruno Accioly

    What if I wanted to make show a hidden DIV for the user every time a post was published?

    Any hints on that?

    • Ritesh Sanap

      What you are saying is possible but it is more complex where it requires a seperate table in mysql to keep track of users who have viewed post and AJAX (Optional) to notify users on the site in real time. whereas the above solution is quite simple and uses WordPress.

      if you want live notifications follow the link posted by “mirditori” in the comments. I guess that will be your best bet, you can install that plugin and afterwards you can tweak it to show the div like you want.