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.
You can also connect with us on Twitter, LinkedIn, and Facebook.
You are right, I never heard about wp cron job before this. Let’s see how this will affect site.
I want to ask you if I disable default wp cron job and forget to add real cron job. How this will affect a WordPress site ?
As I have mentioned, the Cron jobs are required if you want WordPress to do the scheduled task. If you delete it and don’t add a real task, it will directly impact the functionality.
Adding a real Cron Job helps to minimize the CPU usage.
This is one of those techie issues that people like me (not a techie at all) prefer to ignore.
But you make a good case for the fact that it must be dealt with.
As you advise, if you have shared hosting, your web host will gladly help you out with this… step by step.
Especially if you have a good and reputable host like Bluehost, HostGator or similar.
That’s why customer support is such an important part of your hosting package.
I have managed hosting on my blog (Krishna WorldWide), so things like this are really easy… just have my web host do it for me.
But I also have sites on shared hosting, and so I will certainly tackle this issue with the help of the host I have for those sites.
This article has equipped me with all the understanding I need to make sure this gets done.
You’re right. Most of the people avoid such technical stuff because no one wants to take a chance to break his/her website.
It happens commonly for the shared hosting users. That’s why I always recommend contacting the customer support whenever required. I am sure, your managed hosting is taking care of everything.
Thanks for sharing your views.
Thanks Ravi. I’d been wondering about scheduled tasks in WordPress and how they worked. Setting it up the way you say, every 30 minutes through a real cron job puts less load on the server because it will run once every 30 minutes instead of all the time on a very busy website. On the other hand, there won’t be as much granularity in when a task is handled because it can only happen at 30 minute intervals, which is probably more than enough for most tasks.