How to Replace the WordPress Cron with a cPanel Cron Job

>How to Replace the WordPress Cron with a cPanel Cron Job
  • replace cron job wordpress

Cron (wp-cron.php) is a built-in WordPress feature which handles your website’s scheduled events.

If you schedule a post or a backup, for example, WordPress cron will check for them, and then launch them.

The thing is that WordPress cron is executed when someone visits your website – every single time someone visits your website, that is.

So, if you have a lot of traffic, then having WordPress cron triggering every time someone visits your website will create a lot of calls to the wp-cron.php file, which can impact your server’s resources like the WordPress Heartbeat API does, which I discussed in our previous post.

Therefore, it’s strongly recommended that you disable the built-in WordPress cron and create a cron job on your server, which will execute at specific intervals of time.

How to disable WordPress cron

For this, you’ll need to be able to access your WordPress files.

1. Find the wp-confing.php file, which should usually be in the /public_html/ folder.

Or, if you have more than one WordPress website on your account, and you need to access one of your add-on domains’ files, then you need to look in its own folder: /public_html/yourdomain.com/.

2. Once you found the wp-config.php file, edit it and add the below code, right above the /* That’s all, stop editing! Happy blogging. */ line.

define('DISABLE_WP_CRON', true);

Disable WordPress Cron

3. Save the file.

How to add a Cron Job in cPanel

1. Log in to your web host’s cPanel.

2. Find the Cron Jobs tool and click on it – its location depends from web host to web host.

3. Under Add a New Cron Job, at Common Settings, choose Twice Per Hour (0,30 * * * *).

This means that the cron job will execute every 30 minutes, instead of executing every time a user visits your website.

It’s not optimal to add a cron job to run in less than 30 minutes! You can choose to run it once per hour if you wish, but not in less than 30 minutes!

4. In the Command field, add this line:

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

Don’t forget to replace yourdomain.com with your actual domain name!

Or you can add this line instead:

cd /home/username/public_html; /usr/local/bin/php -q wp-cron.php

Don’t forget to replace username with your actual cPanel username.

5. Click the Add New Cron Job button.

add cron job in cpanel

Now your WordPress website will run scheduled tasks in an optimal way, without creating excessive calls that will burden your server’s resources!

cPanel Cron Job Alternative

Since some web hosts might not have this feature, or it won’t work properly, you could try an external tool, such as EasyCron, which offers different solutions for different needs, including a free package!

That’s a wrap

Hope you liked the tutorial and found it comprehensive.

Don’t forget to share it in order to help out others!

You can also follow us on Twitter and subscribe to our YouTube channel.

If you want to start your own WordPress blog, or need a website for your business, our WordPress services are at your disposal!

By |2018-08-14T03:10:53+00:00April 11th, 2018|Customization, Fix, WordPress|0 Comments

Leave A Comment

Subscribe
SIGN ME UP

All Aboard!

Get WordPress guides and tutorials right in your inbox once per week, plus some cool   offers from time to time!
close-link