How to replace the wordpress cron with a real cron job
Because WordPress has to work on all sort of different platforms, OS’s and configurations, it can’t rely that there will be a cronjob service on the server that can handle scheduled tasks. This is why WordPress developers have created a workaround – the wp-cron.php file in your main WordPress folder is executed every time someone loads a page. It then checks if there’s a scheduled task to be done and executes it if necessary.
However, in some cases, this file may become the target of a DOS attack, or caching plugins can interfere with its execution which can cause either a lot of server load or the scheduled tasks may not execute properly and timely. This is why you can substitute this constant file execution with a real cron job.
First, you need to disable the script to be executed every time someone loads one of your pages. To do this, open the wp-config.php file in your main WordPress folder and add the following line before the “/* That’s all, stop editing! Happy blogging. */” line:
Once you do that, you need to setup a real cron job and execute the wp-cron.php file with it. You don’t want to trigger it too often – 30 minutes should be fine for most of the websites. To do this, login to your cPanel and go to the Cron jobs tool located in the Advanced section.
Then, add the following command to be executed every 30 minutes:
wget –q –O – http://yourdomain.com/wp–cron.php?doing_wp_cron >/dev/null 2>&1
You need to replace yourdomain.com with your actual domain name. The Cron jobs tool has some of the most common schedules preset, so you can just select Every 30 minutes from the minutes drop-down and place a “*” symbol in the others.