QUICK TIP - Change WordPress Cron with a Real Cron Job

0 65,617
grunt_js_automate_web_development_tasks_and_save_your_time.jpg | A&H Business Technology
Related posts

Change WordPress Cron with a Real Cron Job – WordPress uses a file called wp-cron.php. It has many functions depend on our setting. Thus, why do we need to change it to a real cron job?

Cron job’s functions and the reasons why we need to Change WordPress Cron with a Real Cron Job


There are some main features that cron job can do:

  • a virtual cron job, or
  • scheduled task in order to automate things like publishing scheduled posts,
  • checking for plugin or theme updates,
  • sending email notifications and
  • more …

The reasons why we need to Change WordPress Cron with a Real Cron Job

By default, WordPress is setup to call wp-cron.php every time someone visits your WordPress website when a scheduled task is present, to basically ask “is it time to do anything yet?”.

On low traffic sites this is perfectly fine, but when visitors roll in, checking multiple times for scheduled tasks can be very inefficient and lead to resource usage problems for your server, plus make your website load slower.

Therefore, in this situation, visitors will active the functions of cron job and this is not the aim that we really expect.

So, “real cron job” here means it can run automatically by schedule without depending on visitors.

  1. Thus, we can schedule on the suitable time periods that does not affect website performance.
  2. The job task will run faster and without errors by conflict among scripts or plugins when visitors access on your website.

How to Change WordPress Cron with a Real Cron Job

There are two main steps that you need to conduct. It is so simple and easy to implement on cpanel on your hosting. So, read carefully before you do.

Disable default wp-cron.php behaviour

We can easily tell WordPress to let us handle the execution of wp-cron.php with the wp-config.php file.

Step 1: Open your wp-config.php file with the cPanel File Manager Code Editor

Step 2: Go to the bottom of the database settings in wp-config.php typically around line 37.

Add the code below highlighted in red:

Step 3: Click Save

Now WordPress will not automatically run the wp-cron.php script each time your site gets a new visitor.

Setup manual cron job for wp-cron.php

We do not want to leave WordPress without any ability to automate tasks it might need to do. But at least now that it is not running for every single visitor, we can have way more control over when these tasks take place.

Step 1: Login into cPanel

Step 2: Under the Advanced section, click on Cron Jobs.

Step 3: Select an appropriate time from the Common Settings drop-down.

Note : An appropriate time means if you had selected ‘Hourly’ for the ‘Schedule Wall Posts’ from the plugin settings then should select ‘Once an hour’ from common settings.

Change WordPress Cron with a Real Cron JobStep 4: Finally fill in the code to run our cron job and click Add New Cron Job.

You can choose 1 command line above to insert. You can email to check with your web-hosting administrator  or you can test by yourself.

For example, you can try the first line in first step. If there are no errors, you will keep this line. If not, you will select the second one.

Where username is your cPanel user name.

Keep in mind that the /home/userna5/public_html path would be for a primary domain, if you’re using an add-on domain, or have WordPress installed in a sub-directory you’ll want to be sure to update your path.

Step 5: You should see that your new cron job was added successfully.

Now your WordPress website should be safely running scheduled tasks via the wp-cron.php script, but only at set intervals.

TinyURL for this post: https://tinyurl.com/yxqh2hkz

Sorry, The Comment Form Is Temporarily Closed At This Time
You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More