Wordpress uses wp-cron.php to schedule the task for the wordpress websites, such as scheduling a post to publish, checking for the new wordpress version, plugin, theme updates, email sending notification, etc. However, there is a limitation. By default, wp-cron requires a back-end or front-end visit to function. Otherwise, wp-cron can't run the scheduled task. Wordpress website with high traffic doesn't occur any issue, but a website with low traffic can cause missing schedule tasks.
Another issue that can occur with wp-cron is performance. WP-cron works by checking with every page load. When a wordpress page loads, it will check for the list of scheduled tasks to see what needs to run. Website pages will check for the scheduled task each time it is visited. On a high-traffic website, this can lead to high resource usage and make your website speed slower.
How to disable default wp-cron.php behavior?
Please refer to the following steps to disable Wp-cron to run on cPanel.
- Log in to your cPanel account.
- Go to your Wordpress website path.
- Open your Wp-config.php file.
- Inside wp-config.php, add the below line after the database settings.
- Finally, click on the Save Changes button.
Now, Wordpress will not run the wp-cron.php script each time the website has a new visitor after making these changes.
How to set up a manual cron job for wp-cron.php?
We shouldn't stop all the automatic tasks on the Wordpress website entirely as some of the tasks could be very important. However, it shouldn't run with every single visitor. We can set up control on how these tasks can run. We can set the wp-cron.php to run every 12 hours. It will run two times in 24 hours. It is better in comparison to the default behavior of wp-cron.php. You can set up this time as per your website requirement.
- Log in to your cPanel.
- In the advanced section, click on the Cron Jobs.
- At the common settings drop-down, select Twice Per Day. Once you choose, it will automatically fill the hour section with Every Twelve Hours (0,12).
- Inside the command section, add the below command. Replace the cPanel_user with your cPanel username. Here, we have used the path of the primary domain. If you want to do this for the addon or sub-domain within the cPanel, you can change the path accordingly.
cd /home/cPanel_username/public_html; php -q wp-cron.php
- Finally, click on Add New Cron job button.
After setting up the manual cron job for wp-cron.php, your Wordpress website should run the scheduled task at the set intervals.