In WordPress, the wp-cron.php file is used as a means to automate scheduled tasks. It can be used to check theme/plugin updates, publish scheduled posts, manage email notifications, etc.
As per default settings, WordPress automatically calls this file (wp-cron.php), every time a visitor comes to your website when any scheduled task is there. Its purpose is to inquire whether there is something to be done.
This is absolutely fine when the traffic is low. The low traffic ensures the file is not called multiple times. However, when the traffic increases substantially, the checking process is undertaken multiple times making it a resource-heavy process. This can unnecessarily increase usage resource usage problems and even lead to server downtimes. No one likes a slow loading website.
How to Disable default wp-cron.php behavior
You can easily control the wp-cron.php file execution through the wp-config.php file. Here’s how:
- Open the wp-config.php file from the ‘cPanel File Manager Code Editor’.
- Now, move towards the bottom of the wp-config.php in the database settings.
- Most likely, you should look for line 37, where you have to add the below mentioned code:
Manually Setting Up cron job for wp-cron.php
Now, you may leave WordPress with no ability to handle task automation wven when it needs to. With above change, WP won’t be running processes for every single visitor. Which means you can better regulate how and when the file will execute tasks.
As per our experience, most sites will be perfectly fine to run the process every 6-8 hours or so. This ensures that the process is executed around 3-4 times in a day. That, when compared to earlier hundreds of process executions, means the resource usage is far less. Here’s how you can set the timing of process execution.
- Log into the cPanel with valid username and password.
- Go to the ‘Advanced section’ and enter the ‘Cron Jobs’ by clicking on it.
- First, choose ‘Once an hour’ under the drop down in ‘Common Settings’.
- Next, select ‘Every 6 hours’ further under the ‘Hour’ drop-down menu.
- In the end, enter the code to execute our cron job and create a new Cron Job by clicking on ‘Add New Cron Job’.
- cd /home/userna5/public_html; php -q wp-cron.php
- Note: Here, enter your cPanel user name in place of userna5
Remember, that the /home/userna5/public_html is valid for your primary domain. In case, there is an additional domain, you will have to update the path in the sub-directory as well.