Disable WordPress Cron wp-cron and Activate External Cron Jobs

WordPress has a built-in WordPress cron task scheduler known as wp-cron. This cron scheduler can be used to perform various tasks at predetermined intervals, such as creating scheduled backup, publishing scheduled posts, checking for updates, and running plugin tasks. However, wp-cron can sometimes cause performance issues, especially on high-traffic websites but there is a way to disable wp-cron and activate external cron jobs.

WordPress Activate External Cron Jobs. Disable WordPress Cron

In this article, we’ll go through the steps required to disabled WordPress cron and to activate external cron jobs.

Identify the Current WordPress Cron Job System

Before we can start the process of disabling wp-cron and activating external cron jobs, we need to find out which system is currently in use. There are two possibilities here:

  • Linux Cron: This is a system-level task scheduler that runs on the server itself. It can be used to run tasks at specific times or intervals.
  • cPanel Cron: This is a task scheduler that is built into the cPanel hosting control panel. It can be used to run tasks at specific times or intervals.

If you’re not sure which system your hosting provider uses, you can contact them and ask.

Disable wp-cron Job

Once you know which cron system is in use, the next step is to disable wp-cron. To do this, you need to add the following line of code to your wp-config.php file:

Ballerina
define('DISABLE_WP_CRON', true);

This code tells WordPress not to run wp-cron automatically. Once you’ve added this code, you’ll need to set up an external cron job to run the wp-cron.php file on a regular basis.

Set Up an External Cron Job

To set up an external cron job, you’ll need to use either Linux Cron or cPanel Cron, depending on which system your hosting provider uses. Here are the steps for each system:

Linux Cron:

  1. Log in to your server using SSH.
  2. Run the following command to open the crontab editor:

One of the critical tasks in running a website is to ensure that you have a backup of your data in case of any data loss or corruption. WP Staging is a popular plugin used to create staging environments on WordPress websites. It also provides a backup feature that allows you to schedule backups of your website data.

In this article, we will guide you on how to disable the normal WordPress wp-cron jobs and use an external cron for the backup plugin WP Staging and for all other plugins that relie on cron jobs.

bash
crontab -e
  1. Add the following line of code to the crontab file:
bash
*/15 * * * * /usr/bin/php /path/to/your/wordpress/installation/wp-cron.php > /dev/null 2>&1

This code tells the system to run the wp-cron.php file every 15 minutes. Make sure to replace “/path/to/your/wordpress/installation/” with the actual path to your WordPress installation.

  1. Save and close the crontab file.

cPanel Cron:

  1. Log in to cPanel and go to the Cron Jobs section.
  2. Click on the “Add New Cron Job” button.
  3. In the “Command” field, add the following code:
bash
/usr/bin/php /home/username/public_html/wp-cron.php

Make sure to replace “username” with your actual cPanel username.

  1. Set the interval to “Every 15 minutes”.
  2. Click on the “Add Cron Job” button to save the changes.

That’s it! You’ve now disabled wp-cron and set up an external cron job to run the wp-cron.php file at regular intervals.

Conclusion

Disabling wp-cron and activating external cron jobs can help improve the performance of your WordPress website, especially if you have a lot of scheduled tasks. By following the steps outlined in this article, you can easily set up an external cron job and ensure that your scheduled tasks are running smoothly. If you have any questions or run into any issues, don’t hesitate to contact your hosting provider for assistance.

Related Articles