Back to Top

How to create Cron jobs in WordPress?

Cron job in Wordpress

In this article, I will explain you about the fundamentals of the WordPress Cron Job.Cron is basically a task scheduler that periodically on a given schedule.

WordPress Cron API is quite easy to understand but before you dive into it, make sure you’re familiar with WordPress action and filter hooks.WordPress has a own Cron API which allows us to schedule events and to execute task for a future purpose.

Let’s take a look into code snippet.

Here, we have used two functions for task scheduling and are wp_schedule_event and wp_next_scheduled.

You just need to place above code into the functions.php file and yes here i have insert a post but you can write any code or functionality you want to execute while cron runs.

If you don’t want the automatic cron to run while you’re debugging, then add following line of code into your wp-config.php file

You may also like:

WordPress Shortcode for Bootstrap Alert box
Disable updates for specific plugin in WordPress
Introduction to Transient API in WordPress

That’s all about to adding a cron job.Thank you for reading and hope you enjoyed it.

Feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (1)

  1. Great post.
    You may can use this useful module to create real wp cron: https://wordpress.org/plugins/easycron/.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How BlockChain and Ethereum works?

Posted on 6 years ago

Bhumi

Learn about InnoDB MySQL Storage Engine

Posted on 12 years ago

Bhumi