How to use a server cron instead of WP-Cron
Below is a guide on how to use your server’s cron instead of WordPress’s built-in cron function.
First, it’s worth explaining the difference between them:
- WP-Cron is a function that lets you schedule tasks to run at certain intervals. However, running those tasks depends on site traffic, which can be unreliable if your site doesn’t get regular visits to trigger the cron.
- A server cron is a system-level tool that can run tasks at certain intervals regardless of whether your site is being visited.
1. Disabling WP-Cron
Section titled “1. Disabling WP-Cron”First you need to disable the default WP-Cron. Open the wp-config.php file and add the following line of code:
define('DISABLE_WP_CRON', true);This prevents WordPress from running its cron tasks.
2. Setting up the cron on the server
Section titled “2. Setting up the cron on the server”Next, on your server/hosting you need to add a new cron job that will run the tasks WordPress used to handle. The exact steps for setting up a cron job depend on your hosting provider, but the process generally consists of the following steps:
- Access your server’s control panel or connect to the server via SSH.
- Find the “Cron Jobs” section.
- Add a new cron job with a URL pointing to the wp-cron.php file:
https://www.yoursite.com/wp-cron.php?doing_wp_cronReplace https://www.yoursite.com with your site’s URL.
This command runs WordPress’s cron tasks at the specified intervals.
3. Testing and monitoring
Section titled “3. Testing and monitoring”After setting up the server cron, it’s important to test and monitor it to make sure the tasks run as expected. Here are a few things to keep in mind:
- Check your site’s error logs for any cron-related problems.
- Monitor your site’s performance and make sure the cron tasks aren’t causing any slowdowns.
- Test the cron job by scheduling it to run at a specific time and verifying that it runs as expected.
And that’s it! By using your server’s cron instead of WordPress’s cron, you can ensure scheduled tasks run reliably without depending on user traffic.
Was this page helpful?
Thanks for the feedback!
Sorry to hear that. Tell me what was missing and how I can help →