Key points:
- WP-Cron’s reliance on page loads creates performance and reliability issues
- For professional WordPress applications and reliable task automation, disable default WP-Cron.
- Choose from three implementation methods: Manual configuration, plugin solutions, and hosting control panels.
- Optimize performance through proper task intervals, logging, and database management.
Crons are job schedulers that allow tasks to run automatically at specified intervals, without manual input. In the world of WordPress, this functionality allows you to automate tasks like scheduling posts, checking for updates, or managing backups.
When crons fail to execute properly, it can create serious problems for your website – slowing down operations or even causing functionality to break.
For WordPress admins that want to take charge, we’re going to explore how crons work within WordPress, what can go wrong, and how you can improve their reliability. We’ll also explore useful tools and best practices that can help ensure your crons run smoothly, keeping your site running like clockwork.
What is WP-Cron and how does it work?
WP Cron is WordPress’s built-in system for scheduling tasks like publishing posts at a specific time, checking for updates, or sending out regular emails.
Unlike traditional cron jobs, which run on a server at fixed intervals, WP Cron works by triggering tasks only when someone visits your website. This means it relies on page loads to check if any scheduled tasks need to be executed.
The system is handled by the wp-cron.php file, which connects to the WordPress database to check for pending tasks. These tasks are stored as scheduled events in the wp_options
table under the “cron” entry. If you’re using a custom database table prefix, WP Cron will look for tasks in the table with your custom prefix, such as yourprefix_options
.
The limitations of WP-Cron
WP-Cron’s dependence on page visits might have raised some alarms in your mind already.
For low-traffic sites, scheduled tasks just won’t run until someone visits the site, and who knows when that’ll be? High-traffic sites have the opposite problem: Every page load triggers a cron check, which strains resources and impacts performance.
Just in case the risks weren’t clear enough, even the official WordPress documentation doesn’t pull any punches with its disclaimers: “Scheduling errors could occur if you schedule a task for 2:00PM and no page loads occur until 5:00PM… So while you can’t be 100% sure when your task will run, you can be 100% sure that it will run eventually.”
If you’d rather not leave scheduled tasks up to chance or be punished for drawing traffic to your site, you’ll need to take control into your own hands. The first step towards that is disabling WP-Cron.
How to disable WP-Cron
Disabling WP-Cron is relatively straightforward.; Just add the following code to your site’s wp-config file, right above the line that says /* That’s all, stop editing! Happy blogging. */:
define( 'DISABLE_WP_CRON', true );
This will keep WP-Cron from running on page loads, so it’s not triggered by visits to the site. However, you can still call it manually via the wp-cron.php file.
As you might have guessed, though, this will stop all cron jobs from running, which is when you move to the next step: Setting up an alternative cron system for your WordPress site.
Managing WordPress cron jobs: 3 professional approaches
Without WP-Cron, you have three primary methods for keeping your scheduled tasks running smoothly: some manual tweaking, using a plugin, and going through your hosting control panel.
Before getting started, create a full backup of your website, because even the best developers have their fair share of bad days. You don’t want the dreaded White Screen of Death locking you and your users out of your site.
1. Manually
As usual with WordPress, you can tweak some files with a bit of code to get things working how you want them.
Probably the lowest level of cron job management in WordPress, even lower than disabling them altogether, involves adding the following line of code to your wp-config.php:
define( 'WP_CRON_LOCK_TIMEOUT', 900 )
This will prevent cron jobs from running more than once within the specified time period, which is in seconds. In this case, it would cap them at once every 900 seconds or 15 minutes.
This approach is ideal for high-traffic sites that are struggling under the weight of excessive cron jobs. It does little, however, to address the issues of low-traffic sites whose cron jobs might not be executing at all.
For those situations, after disabling WP-Cron in wp-config.php, follow these steps:
- From the command line, open your server’s cron job scheduler:
crontab -e
- Configure a cron job to run every five minutes:
*/5 * * * * wget -q -O - https://yourwebsite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
- List all scheduled cron events and confirm that the new one is on the list:
wp cron event list
You can also use the command line to manage cron jobs beyond just listing them:
- Delete unwanted cron events:
wp cron event delete event_name
- Reschedule important cron events. Replace ‘
+1 hour
’ with your ideal timing:
wp cron event schedule event_name '+1 hour'
Finally, you can redirect access to wp-cron.php by adding rules to your site’s .htaccess:
<Files "wp-cron.php">
Require all denied
Require ip YOUR_SERVER_IP
</Files>
2. Using a plugin
Another option that you’ll almost always have with WordPress is to find a plugin that provides exactly what your site is missing. In this case, it’s WP Crontrol.
WP Crontrol gives you a dashboard from which you can manage cron events across your WordPress site. When you first install and activate the plugin, it comes with a couple of events already set up.
The plugin works by calling up cron events using their hooks and then executing them as functions.
For example, out of the box, it will check for and install plugin updates twice a day by using the wp_update_plugins
hook and executing the wp_update_plugins()
function.
To create your own event using WP Crontrol, here’s what you need to do:
- Click Add Cron Event from the Cron Events tab.
- Choose whether you want to add an existing cron event (you can create one in your functions.php and call it here), an event from a URL, or define one right within the plugin using PHP. We’re going to use the third option.
- In the PHP Code section, enter the code for your event. Here’s an example that sends an automated email:
add_action('send_email_cron_hook', 'send_email_cron_function');
function send_email_cron_function() {
$to = '[email protected]';
$subject = 'Automated Email from Cron Job';
$message = 'Hello, this email was sent automatically via WordPress Cron.';
$headers = ['Content-Type: text/html; charset=UTF-8'];
wp_mail($to, $subject, $message, $headers);
}
- Give the event a name, define a schedule, and then save it.
- When you’re taken back to the list of cron events, click Run now under the new event to test that it works.
3. Using your hosting control panel
A lot of hosts, especially the ones that have specialized in WordPress, will provide a better WP_Cron alternative within their control panels.
WP Engine is one such host, and their Alternate Cron tool addresses the challenges faced by both low and high-traffic websites.
Instead of relying on traffic flow, Alternate Cron checks wp-cron.php every minute for due events. It’s also baked into your hosting and it runs on the server itself, which allows it to act like a true server cron.
Enabling it takes only a few clicks from within the UI: Sites > Your Environment > Utilities > Alternate Cron then toggle the option on and voila!
All these features together make for a solution that’s as reliable as it is easy to use.
Best practices for managing cron jobs in WordPress
- Configure task intervals carefully (e.g., hourly or daily rather than every minute) to reduce server load, especially for resource-intensive tasks like backups, large email batches, or data imports.
- Enable detailed logging and debugging by adding
define('WP_DEBUG', true);
in wp-config.php. Monitor cron executions with tools like WP Crontrol to quickly identify, troubleshoot, and resolve delays or failures. - Optimize database queries within cron tasks by using targeted indexing, selecting only required columns, and avoiding full table scans. Consider caching frequently queried data to further reduce database load.
- Set a reasonable maximum execution time (e.g., 30-60 seconds) within cron jobs to avoid server timeouts or resource exhaustion. Use techniques like batch processing for large tasks.
- Use
wp_schedule_single_event()
to precisely manage timing and execution order, ensuring that high-priority tasks run promptly without delays caused by lower-priority cron jobs. - Review scheduled tasks regularly, removing or rescheduling outdated or permanently failing cron events.
Building reliable WordPress task scheduling
WordPress cron jobs can be tedious to work with, but mishandling them can quickly lead to unreliable automation, wasted resources, and instability in your projects.
Grasping how WP-Cron works demonstrates genuine technical understanding, helping you build more reliable systems.
It’s a step beyond basic WordPress skills – reflecting thoughtful system-level planning and adherence to WordPress development best practices.
Take a moment to evaluate your current schedules, remove outdated tasks, and optimize processes for better performance. Finally, consider integrating professional-grade tools like Advanced Custom Fields (ACF®) to strengthen your workflow.
For more straightforward, practical WordPress advice without hype, keep following the ACF blog – we’re here to provide developer insights and tutorials that actually improve your projects.
For plugin support, please contact our support team directly, as comments aren't actively monitored.