There’s a few plugins that handle email notifications, but they all seem to act like a subscription service for (all) WordPress users.
To notify just you when a post or page is published:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | /** * Send an email notification to the administrator when a post is published. * * @param string $new_status * @param string $old_status * @param object $post */ function wpse_19040_notify_admin_on_publish( $new_status, $old_status, $post ) { if ( $new_status !== 'publish' || $old_status === 'publish' ) return; if ( ! $post_type = get_post_type_object( $post->post_type ) ) return; // Recipient, in this case the administrator email $emailto = get_option( 'admin_email' ); // Email subject, "New {post_type_label}" $subject = 'New ' . $post_type->labels->singular_name; // Email body $message = 'View it: ' . get_permalink( $post->ID ) . "\nEdit it: " . get_edit_post_link( $post->ID ); wp_mail( $emailto, $subject, $message ); } add_action( 'transition_post_status', 'wpse_19040_notify_admin_on_publish', 10, 3 ); |
You can either drop this in your theme’s functions.php
, or save it as a plugin.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.