How to Disable the wp-cron.php in WordPress

From Brian Nelson Ramblings
Jump to: navigation, search

How to Disable the wp-cron.php in WordPress

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 set up to call wp-cron.php every time 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 behavior

We can easily tell WordPress to let us handle the execution of wp-cron.php with the wp-config.php file.

Open your wp-config.php file with your favorite text editor

vim /path/wordpress/install/wp-config.php

Go to the bottom of the database settings in wp-config.php typically around line 37.

Add the code below

 /** The Database Collate type. Don't change this if in doubt. */
 define('DB_COLLATE', );

Add the following line:

 define('DISABLE_WP_CRON', true);

Now each visitor to your site will not invoke wp-cron.php

Setup manual cron job for wp-cron.php

Now wordpress still need to run the wp-cron.php file, so we will now need to a cron job for this.

For most WordPress users having the wp-cron.php script run every 6 hours is perfectly fine. That would be just 4 executions in a day, compared to possibly hundreds, or even thousands if you had a lot of website traffic that day.

crontab -e

Add the following lines, remember to replace your path to the wp-cron.php file

0 */6 * * * /bin/php -f /home/wodpress/install/directory/wp-cron.php > /dev/null 2>&1

No longer will wp-cron.php be taxing your server due to increased traffic to your server.