WordPress cron - how to replace with a cPanel cron job?
WordPress developers have implemented a built-in function for automation called wp_cron which allows you to schedule your posts and events. It is also used for maintenance, update checks and by many plugins which may have some automated features. This solution may have a negative impact on your site performance as well as it may not work as expected in some of situations.
WP Cron vs. cPanel cron job
WP-Cron is not actually a real cron job, but a “fake cron job” that is triggered if someone visits your site. During page load it checks the database if there are any scheduled tasks to execute. The way it works has some drawbacks:
- could affect page load time - if you have a lot of visitors and a lot of scheduled tasks it may have impact on your site speed
- if you have no visits then your scheduled tasks will not be executed
- WordPress cron may fail if there is a bug or conflict between plugins
- cache plugins may prevent the WP-Cron from loading
If you want to avoid those drawbacks you can use a real cron job on your server. This solution is beneficial in two major ways:
- you may be sure that your tasks will be executed on time
- your WordPress website will load faster for your visitors
How to schedule a server cron job?
In this tutorial we will show you how to schedule a real cron job using cPanel.
Step1: Log into your cPanel.
Step2: In cPanel go to "File Manager".
Edit the wp-config.php file which you will find in the root directory of your WordPress website.
Add the following code in a new line:
Save your changes.
Step3: In cPanel go to "Cron Jobs".
You should see the following page:
- In the "Add New Cron Job" section you need to select the time interval. Please note that some hostings may have restrictions on the time interval, for example, you may not be allowed to use the intervals lower than 15 minutes.
- In the "Command" field you need to enter the following line:
wget -q -O - http://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1Remember to replace "http://yourdomain.com" with your real domain name.
- Click on the "Add New Cron Job" button to confirm.
That's all. If you have followed all the steps carefully, your WordPress cron job should be replaced with a real, server cron job. Please note that hostings may have some restrictions on using cron jobs, so if you cannot get it work properly you should contact your hosting support for more help.