I am starting my todays post with a lot of greetings. How are you? hope all of you are very fine, i am also. Today i am sharing a wordpress code snippet which is very valuable for send automatic email all of your blogs user when a new post will publish without any kinds of plugin.
for this, copy this code:
now past it in your wordpress themes 'functions.php' file and save. (change 'itbatayan.com' with your own site name or any things.
Thanks for visiting my blog and reading my article.
for this, copy this code:
function newPostNotify($post_ID) {if you face problem copy code then try here
if( wp_is_post_revision($post_ID) ) return;
global $wpdb;
$get_post_info = get_post($post_ID);
if ( $get_post_info->post_status == 'publish' && $_POST['original_post_status'] != 'publish' ) {
// Get all of the emails from the database
$wp_user_email = $wpdb->get_results("SELECT DISTINCT user_email FROM $wpdb->users");
// Send emails to each of registered users
foreach ( $wp_user_email as $email ) {
// Email subject
$subject = 'A new post published at itbatayan.com';
// Messages:new post url:+ URL
$message = 'View this new post now:' . get_permalink($post_ID);
// Send email
wp_mail($email->user_email, $subject, $message);
}
}
}
add_action('publish_post', 'newPostNotify');
now past it in your wordpress themes 'functions.php' file and save. (change 'itbatayan.com' with your own site name or any things.
Thanks for visiting my blog and reading my article.
0 comments:
Post a Comment
Comments here