How to Add a Real WordPress Cron Job for a Faster Website
August 4th, 2017 | by Ravi Chahar || 5 Comments |
This is a kind of complicated topic for the beginners. First of all, you should know what are WordPress Cron jobs and how can you add a real WordPress Cron job.
Let me ask you something. Don’t you want a fast loading website? Have you tried so hard to reduce the page loading time of your website?
Just like you, most of the people are struggling to deal with this issue.
In WordPress, there is a wp-cron.php file which was added to handle the scheduled tasks. It gets called every time someone visits your website.
This will check whether any scheduled task is in the queue whenever the page loads. It means, it can impact the CPU usage.
And if anything goes wrong and this file couldn’t work properly, the CPU usage would extend and you will be over the capacity which will finally result in the downtime.
In this tutorial, you will learn to add a real WordPress Cron job for better site handling.
Disable the Default WordPress Cron Job
Before adding a real Cron job, you have to disable the default Cron job.
As mentioned before, the file gets loaded every time someone opens any page of your website. You have to disable this activity.
It can be done by editing the wp-config.php file.
Adding a one line code will do the work. Add this between the PHP tag.
Save the file and from now onwards, WordPress isn’t going to call its Cron job functionality. But you’re not finished yet.
Add a Real WordPress Cron Job from the cPanel
You have to set the real Cron job using the cPanel of your web hosting account. I am sure, it won’t scare. Just follow the steps.
Step 1: – Login and find the “Advanced” section. The interface of the cPanel may be different depending on the web hosting you use.
So no need to worry about. Find the “Cron Jobs” icon and open it.
Step 2: – A new page will open on which, you have to set the Cron jobs’ timing. You will also see a notification that it shouldn’t be set less than 30 minutes.
That’s what you have to do.
Scroll down and in the “Add a New Cron Job” section, you will see many fields to fill using the drop-down menu beside each.
For minutes, you have to choose 30 minutes. For rest of the fields, choose the starting option including (*).
To apply it, you have to run a command.
NOTE: Replace the “user” with the real username of your cPanel. Let’s say it’s “site14”. You have to use what you fill to log in.
Click on the “Add New Cron Job” button and you’re done.
You have saved your website from getting messed up due to the default Cron job. Sometimes due to any plugin conflict or anything else, the job doesn’t get completed which directly affect the CPU usage.
By setting up the timing, the execution will be done in a systematic manner.
I hope Now You Can Easily Add a Real WordPress Cron Job
These type of concepts aren’t known to most of the WordPress users.
But if you ask your web hosting customer support, they will let you know everything. Whenever your website goes down, they recommend you to add a real WordPress Cron job.
On the shared hosting, the overuse of the CPU is one of the biggest problems because of the number of scripts running on your website.
I am sure, from now onwards, you will not face such kind of problem because you know how to fix it. If you still have any doubt, feel free to clear it.