By default, automatic task handling in WordPress is controlled by wp-cron.php. This script is used by WordPress to run scheduled tasks for your WordPress site. Unfortunately, this file is set to be called on every page view, even when it isn't needed, which in turn can cause higher than needed use of resources on the server.
WordPress defaults to this behavior because some hosts do not allow manual cron jobs to be created and the tasks have to be carried out by this script instead. Since WordPress can be installed on so many different hosts, the developers are trying to make sure it will run as expected whatever the environment.
Once a blog begins to add users and traffic increases, this can cause issues for your account because the script is called for every single page view. Fortunately, it's fairly easy to disable this default behavior and set up a proper cron job through cPanel for WordPress task management. This will be a much more efficient way to run the tasks needed for WordPress, and can even optimize your WordPress site.
Disabling wp-cron.php in WordPress
- Begin by logging into your cPanel account.
- Enter the File Manager area of cPanel by clicking on the File Manager icon under the Files area of your cPanel home page.
- The wp-config.php which we need to add a line to is located in the directory where you have installed WordPress. In our example, we have installed WordPress to wp.whhsupport.com so our path will be public_html/wp (the document root for that subdomain).
- If you receive a pop up notification regarding encoding, make sure utf-8 is selected in the drop down menu.
- Add the following code to your wp-config.php file, this can be placed right at the top of the file before your database settings.
- Click the Save Changes button and then the Close button.
- You can now exit the File Manager (by closing the tab or window it is in) and return to the cPanel home page.
We've now disabled wp-cron.php from automatically running each time someone visits a page of our site. But we still want the cron to run so that tasks can be managed, we just want to have a little more control over how often the wp-cron.php script runs.
Setting up a Cron Job to Run wp-cron.php
- Back in the cPanel home page, click on the Cron jobs icon under the Advanced area.
- In the Cron Jobs page, we will set how often the cron will run and the command to run our WordPress cron script.
- For time period, we recommend that you do not run this cron more often than every 5 minutes. In fact, if you do not make frequent updates to your WordPress site, you could even set this to a longer time frame (e.g. every 1 or 2 hours)
- The command you will want to input will be similar to:
php -q /home/userna5/public_html/wp-cron.php
Make sure that you replace userna5 with your actual cPanel user name and that the path to wp-cron.php includes the full path to that file. For this example since I have WordPress installed on wp.whhsupport.com (with the document root of that subdomain being public_html/wp), my command would look like:
php -q /home/whhsup5/public_html/wp/wp-cron.php
- Click the Add New Cron Job button to save your new cron job.
We've now disabled the default WordPress cron behavior and created a more reasonable cron job for WordPress task management.
Keep in mind with these changes that when you make changes to your WordPress site, it may take a few minutes for the changes to appear as the cron will need to run the tasks needed. If you have any questions, please feel free to submit a question in our Support Center.