How to set up WordPress Cron Jobs manually

In the Linux operating system, it is called “Cron” ('chronos', time) to a task scheduled to run at a specific time. In other words, on a certain day of the week and at a certain time, either every five minutes, or in the time interval you want, a compendium of instructions previously stipulated in a file called “crontab“. This file contains the repetitive processes that must be re-executed at the scheduled time.

Now why are scheduled tasks making my site slower? Patience, in this guide we are going to explain everything...

Configuring external Cron Jobs to improve the speed of my WordPress site

For real reason, WordPress has its home chron to execute scheduled operations without human intervention. An example of its usefulness is the scheduled sending of emails, the automatic publication of a post that was opportunely programmed to appear online on that day or that date, or the creation of backups at regular intervals.

But WPcron does not work identically to how it does crontab; in fact, it doesn't even appeal to it despite the fact that the latter will always be running on Linux servers. The operation of WPcron It may even surprise you: it needs visitors. Indeed, a visit to an entry or section of your site triggers the operation of WPcron, which will then search for pending tasks to execute. It is quite singular, and, on the other hand, it contains complications. You will have already noticed that if your site does not enjoy visits at a certain time, a scheduled task, such as the scheduled publication of a post or the sending of a report generated by some component will not occur.

But, on the other hand, if your site has many daily visits, each of those visits activates WPcron again. If in one minute you have ten hits, then WPcron will run ten times, which clearly it is completely useless, in addition to occupying unnecessary resources. If you have content with many visits per minute, you can already assume that so many PHP executions by WPcron are making your site slow.

How to disable WPcron (and how to replace it)

To disable WordPress native cron you must modify a text file called wp-config.php

This file should exist in the root of your site, and when you have a hosting provider that provides cPanel (like Duplika) it's very easy to edit.

supplementary note: if your hosting provider does not have cPanel, you must resort to an FTP access program, such as the free one filezilla.

Enter your cPanel (by typing cpanel.yourSite.com in your browser and logging in with your credentials) and locate the tool as we show you in the screenshot below:

After clicking on the file manager, locate the mentioned file as indicated.

Once you select the file, the “Edit” option will light up in the top toolbar, like this:

After clicking on “Edit”, you will probably come across the following pop-up window:

The message alerts two issues: the first, that you should make a backup copy of the file in case something goes wrong. It's easy to do this beforehand by choosing "Download" instead of "Edit" within the top toolbar. If you want to make a backup of wp-config.php now, simply choose “Cancel” and, with the file in question still selected, press “Download” (screenshot below). Otherwise, ignore this step.

The second question that alerts us refers to the encoding of the file wp-config.php. It is a generic alert, and since we are going to add a line of code to the file without modifying any other aspect, we are going to click directly on "Edit" to start editing.

At last we are seeing the text content of our file wp-config.php

In addition, we check the blue "Save changes" button (which we will press after finishing editing) or the "Close" button, in case we are not sure what we are doing, or we believe that we have mistakenly deleted or modified something wrong. But don't worry, the operation that follows is very easy.

They will look for the first line, the one that reads:

define( 'DISABLE_WP_CRON', true );

In the following screenshot we show you the final result:

Once the line of code has been added, we will click on the blue “Save Changes” button and with this we will have instructed our WordPress installation to ignore its native cron tool.

But as you can imagine, having a tool that allows pre-scheduled automated tasks is NOT something we can overlook, so let's continue with the guide.

How do I set up an external cron for my WordPress?

What we have done in the previous step is deactivate the WPcron which, as we already mentioned, works with each visit; So, we need an alternative (and better) plan to fire scheduled tasks at a specific time or interval.

The key is to call MySite.com/wp-cron.php?doing_wp_cron every certain fixed number of minutes, and in this guide we are going to discuss three ways to achieve it (depending on whether or not you have cPanel or a VPS).

if i have cpanel

Back in your cPanel, scroll through the possible tools until you find the “Cron Jobs” tool icon (screenshot below).

On the screen that opens, locate the following region by scrolling down if necessary:

And schedule your cron job as follows, using the dropdown fields:

To run the cron with PHP directly, we can use:

php -q /home/username/public_html/wp-cron.php

Replacing “user” with your cPanel username.

Another alternative is to use wget as follows:

wget -q -O - https://domain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

Click the blue “Add New Cron Job” button, and you're done! If you were able to do this last step, you don't need to keep reading. We congratulate you on improving the speed of your site, and we wish you good luck in your endeavors. Otherwise, keep reading...

My Hosting provider does NOT provide me with cPanel. How do I solve it?

If your hosting provider doesn't offer you cPanel, you can resolve the call to wp-cron.php with the help of the service you provide EasyCron.

ANDasyCron, although it is a service that requires the creation of an account and tries to make you buy it, it nevertheless offers the FREE option to create a cron job or remote cron job every 20 minutes. It's more than enough for our purposes, so let's create an account on your site right now.

Note: the service is in English, but if you follow our instructions and colored arrows, you will not have problems if you are not familiar with that language.

Then click on the link indicated by the arrow:

In the pop-up window, write your email and type a password of your choice. Once this is done, you will see the following screen, and you will click on the indicated button:

The popup window that will appear will look like this:

This window works like a form where you must complete some fields as indicated below.

And after clicking on the blue “Create Cron Job” button you can successfully complete the creation of a remote call to your cron. If you have completed the steps up to here, you do not need to continue reading, but if you have a VPS then we recommend applying the practice described in the next point.

I have a VPS server: what is the command to create this at the server level?

Excellent. Login to your VPS (SSH) and enter the following command to be able to edit your file crontab.

crontab -e

In the crontab file editing window, add the following command:

wget -q -O - https://domain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

Remember that with the command :wp you can exit the editor.

With this you will have finished creating an external cronjob to WordPress native, not only faster but also more efficient.

Final conclusion

We have explained to you the nature of a cron job, its usefulness, and the particular way it works in WordPress.

We think the benefit of stopping it natively in WordPress to be replaced by a much more consistent external method (and which translates to speed for your site) has become clear.

If you have any doubts, feel free to write to us in the comments, or go to [email protected]

We are here to help you.

Good luck to your site, and thanks for reading.

We are Duplika

Give your site the hosting it deserves

no comments on How to set up WordPress Cron Jobs manually

back to blog

Duplika

Duplika

We are online, we are not a bot :)

I will be back soon

Duplika
Hi 👋
Select the prefered contact method to get in touch.
Connect via:
chat