What is a WordPress Cron Job?
A WordPress Cron is a scheduled task that should run at a fixed time interval.
You can think of a WordPress Cron as your websites reminder to perform a task or function at a fixed time. The tasks that a WordPress Cron will trigger mostly consist of database optimisations such as clearing old auto-saved posts or checking if your plugins need updating.
Why are WordPress Cron jobs used?
WordPress Cron jobs are used by plugin, theme and WordPress core developers to schedule tasks at fixed intervals.
There are a lot of uses for the WordPress Cron job system; with the most notable being:
- Checking for updates to WordPress, themes and plugins.
- Publishing a new post at a scheduled time.
- Clearing the database to remove outdated data.
- Handling recurring subscription orders.
In reality, any task that needs to run periodically will use the WordPress Cron system.
How do I see what WordPress Cron jobs are on my website?
The easiest way to see what Cron jobs your WordPress site will run and when, is to install the WP Crontrol plugin from the WordPress plugin directory.
Once installed you can view the crons by:
- Hovering over the “Tools” button in the main WordPress dashboard menu.
- Clicking “Cron Events”
From this screen, you’ll see a list of each Cron job scheduled to run on your site. Along with its name, arguments, when it will next run, and how often it runs.
Why’s it called a WordPress Cron?
WordPress Cron jobs gain its name from a similar system known merely as Cron Jobs.
The two are both very similar in that they act as a task schedular in a computer-based environment. The difference is that a WordPress Cron is run from within the website, while a regular Cron Job is server-based.
At a glance that may seem the same, but in reality, there’s a big difference between the two. Primary that a WordPress Cron has some substantial limitations that a regular Cron Job doesn’t.
What are the limitations of a WordPress Cron?
The most significant limitation of the WordPress Cron system is that someone must visit the website for the scheduled task to run.
When you think about it, that’s a pretty big flaw with the WordPress Cron system. After all, if you set your alarm for 5:30 and it only went off when you check your phone you’d be a little peeved.
So, why bother? The simple answer is that an active website with constant traffic won’t have a problem. The tasks will run more or less on time, with minimal impact on the visitor.
A website with fewer visitors will suffer a little. Overdue tasks get backed up, and the visitor unfortunate enough to trigger the Cron system will have a slow loading experience; as every outstanding job runs.
How to fix the WordPress Cron systems limitations
The easiest way to fix the WordPress Cron systems limitations is to replace it with regular, server-based Cron Jobs.
Replacing the WordPress Cron system isn’t as daunting as you think; in fact, it’s doable within 5 minutes.
How to replace WordPress Cron Jobs with real Cron Jobs
To replace a WordPress Cron with a regular, more reliable Cron Job, you need to disable the WordPress Cron and then set up a server-side Cron.
Step 1: Disable WordPress Cron
The first step requires you to disable the WordPress Cron. What this means is; instead of running the tasks when someone visits the website, it only runs when a specific URL is visited.
Namely, the URL will be https://yourdomain.co.uk/wp-cron.php?doing_wp_cron.
To disable the system you’ll need to:
- Connect to your web server through FTP, or your control panels file manager.
- Find and open the wp-config.php file.
- After the opening <?php add the line define( ‘ DISABLE_WP_CRON ‘ , true );
Here’s that line of code again, for ease of copying.
define( 'DISABLE_WP_CRON' , true );
Step 2: Setup the server Cron
Setting up a server Cron can be accomplished in several ways; for the majority, the process will be as follows.
- Log in to your web hosting control panel.
- Look for a section called “Crons” or “Cron jobs”
- Click on the option to add new Cron jobs.
- Select 15 minutes as the interval.
- Enter the command wget -q -O – “http://yourwebsite.com/wp-cron.php?doing_wp_cron” >/dev/null 2>&1
- Save the new Cron job, and you’re all good to go.
Here’s that command again.
wget -q -O - "https://yourwebsite.co.uk/wp-cron.php?doing_wp_cron" >/dev/null 2>&1
Remember to replace https://yourwebsite.co.uk with the actual URL of your website.
After following these steps, your web server will now navigate to your websites wp-cron.php file every 15 minutes, triggering WordPress to run any tasks that are due.
Having a 15 minute lead time is recommended; however, that does mean that tasks could occasionally be a little late.
What is a WordPress Cron?
A WordPress Cron is a task that’s scheduled within WordPress to run periodically at a specific time.