Disabling the default WordPress cron and replacing it with a cron job

WordPress has a built-in cron system for scheduling tasks like updates and publishing scheduled posts. Unlike Unix cron, which runs at fixed intervals regardless of activity, WordPress cron relies on website traffic. It triggers wp-cron.php when a visitor accesses the website, meaning tasks may not run on time if traffic is low.

What are some benefits and downsides of the WordPress cron?

The default WordPress cron system has both advantages and drawbacks. When a website has high traffic, wp-cron.php runs frequently, ensuring timely updates and fresh data for visitors. This is beneficial for websites that rely on real-time plugin updates.

However, if a website has low or no traffic for a period, scheduled tasks may not run until a visitor arrives, potentially causing outdated content. Additionally, if wp-cron.php takes too long to execute, visitors may see delayed or inaccurate data.

Another downside is that multiple cron instances can run simultaneously if tasks take too long to complete, further delaying execution. High traffic can also lead to increased system resource usage, especially if bots crawl the website. In some cases, WordPress cron may slow down page loading times, negatively impacting user experience.

How to reduce the WordPress cron execution interval?

To try and reduce the downsides of the default WordPress cron mechanism, you can add the following line to the WordPress configuration file:

define( 'WP_CRON_LOCK_TIMEOUT', 3600 );

This line limits the execution of wp-cron.php to once per hour, which is typically sufficient for most websites and scheduled tasks. It also helps reduce system resource usage and minimizes the impact on page load times, improving overall website performance.

How to replace the WordPress cron with a cron job?

To replace the WordPress cron with a regular cron job on our servers, you need to:

  1. Disable the default WordPress cron execution on page visits. To do this, go to your hosting Control Panel > File Manager section, open the wp-config.php file, and add the following line:
    define('DISABLE_WP_CRON', true);This prevents wp-cron.php from running automatically when a visitor accesses your website, reducing server load and improving performance, especially on high-traffic websites.

  2. Set up the cron job through the Cron Jobs section of the hosting Control Panel. There are multiple ways to run the WordPress cron, and you can configure it in two different ways within the hosting Control Panel. You can either enter the command directly when setting up the cron job or create a wrapper script and set it up as a cron job instead.


    • Replace $HOME/www/www with the correct directory of your WordPress website (for the main website just keep it as is, for the "blog" subdomain: $HOME/www/blog).
    • Replace YOUR_DOMAIN.com with the exact domain or subdomain of your WordPress website.

    Using WP-CLI:wp cron event run --due-now --path=$HOME/www/www > /dev/nullUsing a GET request:
    GET "http://YOUR_DOMAIN.com/wp-cron.php" > /dev/null
    Or, you could create a wrapper script, and then set it up to run as a cron job. You will first need to create the wrapper script through the "File Manager" section of the hosting Control Panel. Create the script in a directory of your choice, such as /private/ or the directory where your WordPress website is installed (/www/www for the main domain name), name it cron.sh, and add the following code block into it:

    Using WP-CLI:
    #!/bin/bash
    wp cron event run --due-now --path=/home/example/www/www > /dev/null
    Using a GET request:
    #!/bin/bash
    GET "http://YOUR_DOMAIN.com/wp-cron.php" > /dev/null
  3. The WordPress cron will now run correctly at the specified interval to execute any pending scheduled tasks without relying on visitors to access your website and without increasing the page load time when visitors actually access and use your website.

For more details, check out our article on the Cron Jobs section of the Hosting Control Panel to get familiar with the interface and available options.