Use cron to schedule events in your blog

WordPress has the ability to schedule event using built in cron. So you can use this to schedule events on your blog. In this sample an email is sent out hourly to specified address however you could schedule nearly anything.

Code Snippet:

if (!wp_next_scheduled('do_hook')) {
wp_schedule_event( time(), 'hourly', 'my_task_hook' );

add_action( 'do_hook', 'do_function' );
function do_function() {
wp_mail('you@wpsnipp.com', 'Automatic email', 'Hello, this is an automatically scheduled email from WordPress.');

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!