- Home
- Knowledge Base
- WordPress
- 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
- Access your WordPress files. You can do this via cPanel’s File Manager or using an FTP client such as FileZilla.
- Navigate to the root directory of your WordPress installation. Typically, this is the public_html folder.
- Open the
wp-config.php
file for editing. - Insert the following line of code just before the line that says
/* That's all, stop editing! Happy publishing. */
:
define('DISABLE_WP_CRON', true);
- 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
- Log in to your cPanel account.
- In the “Advanced” section, click on “Cron jobs.”
- 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.
- 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
- 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. So2>
redirects the error message.&1
: This tells the system to direct the stderr (standard error, denoted by2
) to the same location as stdout (standard output, denoted by1
). So2>&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.
Related Articles
- Understanding and Securing the WordPress REST API
- How to Fix the WordPress White Screen of Death
- 10 Basic Steps for Troubleshooting WordPress Errors
- How to Fix your WordPress Site When It’s Experiencing a Critical Error
- What is WP-CLI? A Comprehensive Guide by SmartHost
- How to Change Sender Name in Outgoing WordPress Emails
Leave A Comment