Disable WordPress Cron and Use Real Cron Job
Normally, there is no way PHP can run without a page being loaded or without it being executed from CLI. So your WordPress cron how does it go about? Firstly what’s WordPress cron?
What is Cron?
Cron Jobs are software utility that can trigger a defined function based on time given to it, when you receive update notifications in your WordPress Admin it’s done by cron job.
How does WordPress execute this?
Actually, this is not done by the system cron; Once a user hits your page, before page loads and everything is set WordPress uses that time to run it’s cron but some wouldn’t know. This can affect your site loading time because WordPress is busy dealing with daily, hourly, weekly checks once a page loads but what if we stop this and hand over the job to the main system cron? 😉 Pretty cool ye?
- Let’s tell WordPress first to stop checking cron jobs on page load by adding this to your wp-config.php
I’d suggest you add it after
Now WordPress won’t check Cron on page loads again and you won’t receive update notifications at this moment.
- If you load this page http://yourwpsite.com/wp-cron.php?doing_wp_cron directly on the browser, it does the checking. So we are gonna add a Cron Job to be doing this for us.
For cPanel Users
- Login to your cPanel and move to the Cron Jobs tab then open it. Add new cron and set timing at least every 5 minutes then add this to command
/usr/bin/curl http://yourwpsite.com/wp-cron.php?doing_wp_cron > /dev/null
For VPS Users
If you are using your own server or a VPS which is running Linux, you can still set this up without cPanel. Just install cURL into your system and run this:
$ sudo crontab -e -u www-data
To the end of the last line, add this
*/5 * * * * /usr/bin/curl http://mywpsite.com/wp-cron.php?doing_wp_cron > /dev/null
then save and exit with CTRL+X. You are done setting cron to check the website every 5mins to update cron.