Optimize WordPress: replace wp_cron with a real Cron job

Have you ever scheduled a post or a newsletter in WordPress only to see nothing happened and the schedule was missed? Here’s why and how to solve this for good!

WordPress comes with a built in function for automation called wp_cron. It is used for maintenance, automatic update checks, to publish scheduled posts, and by many plugins with various automated features. But it is not perfect.

This is because wp_cron is not actually a Cron job, but a “pseudo Cron job” that fires when a page is loaded. So when someone visits you site, wp_cron is fired during page load, and checks the database to see if there is any scheduled action to take.

It does the job, but has two major downsides:
– If you don’t get visits during a given period, any scheduled actions will not be triggered.
– Loading wp_cron during every page load negatively affects your site speed (and if there is a scheduled action to take, an unlucky visitor may have to wait before the page actually shows).

Here’s a simple tweak to replace wp_cron with a real Cron job and solve these issues.

Setting a real Cron job to replace wp_cron

Option #1: Through your hosting cPanel

1. Login to your host’s cPanel and go to “cron jobs”.

Cron jobs section in cPanel

2. Under the “add new cron job” section, choose a 15 minutes interval (you may choose any other interval, but this is a quite common setting and will do in most cases).

Setting a Cron job to every 15 minutes

3. In the “command” field, paste the following line (just change YOURWEBSITE.COM with the actual URL of your WP site!)

wget -q -O - http://YOURWEBSITE.COM/wp-cron.php >/dev/null 2>&1


4. Click “Add New Cron Job” and you are done with this part!

The new Cron job is now set

Option #2: Use a third-party CRON job service

Some hosting provider do not offer adequate CRON functionalities. Some can be unreliable, some only allow a limited number of jobs, or do not allow you to use an interval smaller than an arbitrary minimum. And some hosts even simply don’t provide CRON support at all.

In such case, using a reliable third-party CRON job service is the solution. They will basically “ping” any URL you tell them to at a set interval like clockwork.

I recommend easycron.com, they even have a free plan that should be good enough for most small sites or blog. They also have very affordable paid plans (starting under $8/year) should you need more executions per day and longer timeouts.

Setting up a third-party CRON job with easycron.com is as easy as the name suggests:

1. One you signed up, login to easycron.com and click “Create New Cron Job”

2. In “URL to call”, enter http://YOURWEBSITE.COM/wp-cron.php (just change YOURWEBSITE.COM with the actual URL of your WP site!)

3. Choose an interval to determine how often the job should run

4. Click “Create Cron job” and you are done!

This Cron job will trigger any action that is pending/scheduled in your WordPress every 15 minutes, regardless of your website traffic and without interfering with pageload time.

Now the internal, automatic triggering of wp_cron within WordPress is not needed anymore. It is even unwanted because all it does now is hanging there each time someone visits your sites. This doesn’t make a huge difference on pageload, but still, better get rid of it!

Disable wp_cron

(Warning: you should only do this if you have set up a Cron job, otherwise anything hooked to wp_cron won’t be triggered at all!)

5. Using your FTP program (or file manager in cPanel), download the file called wp-config.php which is located at the root of your WP installation.

6. Open wp-config.php with a text editor and paste the following line.

[pre]define(‘DISABLE_WP_CRON’, true);[/pre]

Add the code to wp-config.php

7. Save and upload wp-config.php back to your server.

That’s it, you’ve just replaced wp_cron with a real Cron job! From now every function hooked to wp_cron will run every 15 minutes no matter what. No more missed schedules, and you have enhanced your site speed on every page load at the same time!

256 bit SSL. 100% secure transactions and data encryption
PayPal Verified
Secured by PayPal
Secure Credit Card payments powered by Stripe