How to and Why You Should Disable WordPress Cron

WordPress is an amazing platform which powers millions of websites and blogs. WordPress can also be extremely inefficient at times and one particular example is wp-cron.php. By default the wp-cron.php is run every single time a page is loaded and if you have a busy blog this can lead to a lot of cron runs, which simply aren’t needed. Whenever someone visits your website, the wp-cron.php will run. This can be taxing to the server, especially if your website gets a lot of traffic. The cron really only needs to run when you make updates, scheduled tasks or scripts, backups of your blog, flushing the spam comments etc. By disable wordpress cron natural behavior to run every time a visitor comes to your blog can be helpful in lowering your resource usage on your WordPress hosting. To understand why this happen, we need to know that the wp-cron.php is not a real cron job. It is in fact a virtual cron that only works when a page is loaded. In short, when a page is requested on the frontend or backend, WordPress will first load wp-cron.php, follow by the necessary page to display to your reader. The loaded wp-cron.php will then check the database to see if there is any thing that needs to be done. In our previous post we have writting about optimize WordPress performance with the wp-config file and in this tutorial, we’ll show you how to disable WordPress cron job and replace it with a real cron job.

How to Disable WordPress Cron

Disable WordPress cron is easy. This is done by adding a one line of code to your wp-config.php file. Open the wp-config.php file with a text editor and paste the following line.

define('DISABLE_WP_CRON', true);

Now wp-cron.php will no longer every time someone loads your pages and ensure that no cron related work in done in any user request. This will reduce some mysql database queries also.

Create a Real WordPress Cron

Cron is actually the task scheduling system used in *nix systems to schedule all sorts of functions on a regular basis. What we’re going to do is schedule cron to run every 5 – 10 minutes via cron. If you’re on a WordPress shared hosting with a service such as Lithium Hosting you will need access to your cPanel to edit the cron job and disable WordPress cron.

Login to your cPanel account, find the Advanced panel, and click the Cron jobs. Under the Add New Cron Job section, choose the interval that you want it to run the cron job. In the Minute field I have set it to run every 15 minutes and i leave blank Common Settings, Hour, Day, Month, and Weekday field. But you can change it according to your liking. In the Command field, enter the following line.

wget -q -O - http://domain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

Don’t forget replace domain.com with your blog URL and click the Add New Cron Job button.

Now What?

That’s it, now you know why you should disable WordPress cron. Now your scheduled tasks will run every 10 minutes regardless of whether your site gets any traffic. To test it out, create a new post and schedule your new post after you have completed the above configuration. Wait and see if the WordPress internal cron job is running. If yes, and you are not see the Missed Schedule status, mean you have successfully create a real cron job for WordPress. If no, go through the steps above and see if you have made any mistake. Alternatively, contact your web hosting and get them to configure and disable WordPress cron for you.