1. Home
  2. Knowledge Base
  3. WordPress
  4. Disabling WP-Cron in WordPress and Setting Up a Manual Cron Job in cPanel

Disabling WP-Cron in WordPress and Setting Up a Manual Cron Job in cPanel

You might want to disable WP-Cron and set up a manual cron job in cPanel for several reasons.

Firstly, WP-Cron is not a true cron job system; it only runs when your WordPress site has visitors. This means that if your website has low traffic or visitors at irregular intervals, scheduled tasks such as publishing scheduled posts or running backups may not occur on time.

On high-traffic sites, WP-Cron can also cause performance issues, as it runs on every single page load. By disabling WP-Cron and setting up a manual cron job, you gain more control over when and how often these tasks are performed.

This can lead to improved site performance, timely execution of scheduled tasks, and a better overall user experience on your website.

Here are the steps to disable the wp-cron function in WordPress and instead set up a manual cron job in cPanel.

Step 1: Disable WP-CRON

  1. Access your WordPress files. You can do this via cPanel’s File Manager or using an FTP client such as FileZilla.
  2. Navigate to the root directory of your WordPress installation. Typically, this is the public_html folder.
  3. Open the wp-config.php file for editing.
  4. Insert the following line of code just before the line that says /* That's all, stop editing! Happy publishing. */:
define('DISABLE_WP_CRON', true);
  1. Save and close the wp-config.php file.

This code disables the wp-cron functionality in WordPress.

Step 2: Set Up a Manual Cron Job in cPanel

  1. Log in to your cPanel account.
  2. In the “Advanced” section, click on “Cron jobs.”
  3. Under the “Add New Cron Job” section, you will see a “Common Settings” dropdown. You can select how often you want the cron job to run. For example, selecting “Once Per Hour” will run the cron job every hour.
  4. In the “Command” field, input the following code, replacing USERNAME with your actual cPanel username:
/usr/bin/php /home/USERNAME/public_html/wp-cron.php >/dev/null 2>&1
  1. Click “Add New Cron Job.”

This command will manually run wp-cron.php at the interval you specified in the “Common Settings” dropdown.

Remember that the timing of cron jobs should be set according to the needs and resources of your website. If you have a website with high traffic and lots of scheduled tasks, you might need to run wp-cron more frequently. However, keep in mind that running it too often can consume resources and slow down your website.

It’s also worth noting that setting the cron job to run too infrequently can result in tasks not being executed in a timely manner (for example, scheduled post publications might be delayed). Therefore, choosing the right frequency is a matter of balance.

Additional Information

What does >/dev/null 2>&1 do ?

The >/dev/null 2>&1 is a command that’s often used in Linux environments. It’s used to handle output and error messages generated by commands.

Let’s break it down:

  • >: This is a redirection operator. It’s used to direct the output of a command to a different location. In this case, it’s directing the output to /dev/null.
  • /dev/null: This is a special file in Unix and Linux systems that discards all data written to it (and returns an end-of-file (EOF) signal if read). When you direct output to /dev/null, you’re essentially discarding it. In other words, you’re “throwing it away.”
  • 2>: This is another redirection operator, but it’s used for error messages. In Unix and Linux, 1 stands for stdout (standard output), 2 stands for stderr (standard error), and > is the redirection operator. So 2> redirects the error message.
  • &1: This tells the system to direct the stderr (standard error, denoted by 2) to the same location as stdout (standard output, denoted by 1). So 2>&1 means “redirect the error output to the same place as the standard output.”

In simple terms, >/dev/null 2>&1 discards all regular output and error messages, which can be useful when you don’t want to store or deal with the output of a command.

Was this article helpful?

Related Articles

Leave A Comment

Go to Top