WordPress uses a file called wp-cron.php
to automate things like publishing scheduled posts, checking for plugin or theme updates, sending email notifications and much more.
Did you know that by default WordPress will load wp-cron.php every single time somebody visits your WordPress website to check if a scheduled task is present.
On low traffic sites this is perfectly fine, but when visitors roll in, checking multiple times for scheduled tasks can be very inefficient and quickly leads to resource usage problems for your WordPress website which can make your website load slower or worse cause errors. The answer to fixing this default behaviour is simple, disable wp-cron.php
and create a real cron job.
To disable the WordPress default wp-cron behaviour add the following line to your wp-config.php file:
Setup a real cronjob
For most WordPress users having the wp-cron.php
script run every 3 hours is perfectly fine. That would be just 8 executions in a day, compared to possibly hundreds, or even thousands if you had a lot of visitors that day.Step 1
- Log into your cPanel.Step 2
- Under the Advanced
section, click Cron Jobs
- Scroll to the Common Settings
drop-down and choose Once Per Hour(0 * * * *)
- Now select Every Third Hour(*/3)
from the Hour
- Finally fill in the code to run our cron job and click Add New Cron Job
Please note that the exact command will depend on your cPanel username, simply replace the word username in the example below with your own cPanel username.
php -q /home/username/public_html/wp-cron.php
is your cPanel user name.
Keep in mind that the /home/username/public_html
path would be for a primary domain, if you're using an addon domain, or have WordPress installed in a sub-directory you'll want to be sure to update your path.Step 6
- Confirm that your new cron job appears in the list of Current Cron Jobs
Your wp-cron file is now setup to run by an independent PHP process so it will not interfere with any visitors page-requests.
Because of this, we highly recommend running wp-cron this way rather than WordPress’s default way, irrespective of size or traffic of your site.