WordPress uses a file called wp-cron.php as a virtual cron job, or scheduled task in order to automate things like publishing scheduled posts, checking for plugin or theme updates, sending email notifications and more.
By default WordPress is setup to call wp-cron.php everytime someone visits your WordPress website when a scheduled task is present, to basically ask “is it time to do anything yet?”.
On low traffic sites this is perfectly fine, but when visitors roll in, checking multiple times for scheduled tasks can be very inefficient and lead to resource usage problems for your server, plus make your website load slower.
Disable default wp-cron.php
- Open your wp-config.php file
- Go to the bottom of the database settings in wp-config.php typically around line 37.
- Add the code below
- Click Save
[php]
/** The Database Collate type. Don’t change this if in doubt. */
define(‘DB_COLLATE’, ”);
define(‘DISABLE_WP_CRON’, ‘true’);
[/php]
We don’t want to leave WordPress without any ability to automate tasks it might need to do. But at least now that it’s not running for every single visitor, we can have way more control over when these tasks take place.
- Log into cPanel
- Under the Advanced section, click on Cron Jobs.
- Select Once an hour from the Common Settings drop-down
- Now select Every 6 hours from the Hour drop-down.
- Finally fill in the code to run our cron job and click Add New Cron Job.
[php]cd /home/username/public_html; php -q wp-cron.php[/php]
Where ‘username’ should be replaced with the username of your site. - You should see that your new cron job was added successfully.
Leave a Reply