Knowledgebase Home / How to Replace a WordPress Cron Job with a Real Cron Job
// View Comments //

How to Replace a WordPress Cron Job with a Real Cron Job

Your slow WordPress load time or failed scheduled posts could be caused by the default WordPress cron function. you can replace it with the operating system’s cron job (Unix/Linux) for improved performance. The actual cron job is the cron scheduler, which is a system process that automatically executes tasks for you in accordance with a predetermined schedule.

Cron is a Unix/Linux tool for scheduling commands or scripts to run periodically. A cron job is a task that schedules repeated actions. In WordPress, it’s managed by WP-Cron, which simulates a system cron. WP-cron is a virtual scheduling system in WordPress. It triggers tasks when a page is loaded but can fail for various reasons such as excessive site traffic and the following reasons.

  • Conflict of plugins
  • DNS-related issues
  • WordPress bugs
  • Use of caching plugins
  • Large server load

In such cases, the best option is to replace WP cron with a real cron job. Let us see how to do it.

Quick Steps

1. Log into cPanel and Navigate the Advanced section.
2. At the bottom click on Cron Jobs.
3. Add Cron Job.
4. Disable real Cron, wp-cron.php via the WordPress configuration file ‘wp-config.php’

How to Replace WP-Cron With a Linux Cron Job

The best way to optimize the efficiency of your WordPress cron jobs is to disable WP-cron which is enabled by default and set up a normal cron job through cPanel, which will run every hour.

Please log into your web hosting control panel, navigate to the “Advanced” section at the bottom or CPanel, and click on Cron Jobs.

cPanel interface cron job

cPanel interface cron job

Within the Cron Job panel, you can add a new task or view/amend existing tasks.

The settings available to trigger a task are:

* * * * * command to execute
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───────────────── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
│ │ │ └─────────────────── month (1 - 12)
│ │ └───────────────────── day of month (1 - 31)
│ └─────────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)
Note: In Cron Jobs "*" means "every"

When adding a new task you can select pre-defined time schedules from the first drop-down list, but we need something slightly different.

cPanel interface cron job

cPanel interface cron job

We need the process to trigger every 15 minutes which needs us to select “Once per 15 Minutes (*/15)” from the second drop-down list, then in each of the other boxes we just need * (Every).

We will use the “wget” command which is a free software package for retrieving files using HTTP, HTTPS, and FTP, the most widely-used Internet protocols. It is a non-interactive command-line tool, so it may easily be called from scripts, cron jobs, terminals without X-Windows support, etc.

The code that we need to execute is

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

You will need to change example.com to the specific domain of your WordPress installation.

Disabling wp-cron.php

You can disable WP-cron by modifying the wp-config.php once a cron job is added with the above steps. The wp-config.php is located in the folder where WordPress is installed. Open the wp-config.php file, add a new line after <?php, then add the following code on the new line

define('DISABLE_WP_CRON', true);

How to test

Set up a new test post that is scheduled for 20 mins in the future and wait. If WordPress has automatically published the post then everything has worked as planned.

Conclusion

Congratulations! You have learned how to set up a WordPress cron job and replace WP cron with a real cron job.


If you have any web hosting questions please feel free to reach out to us. We're happy to help.
Shared Hosting | Reseller Hosting | Managed WordPress Hosting | Fully Managed VPS Hosting

Our Guiding Principles

  • Provide consistent, stable, and reliable web hosting services.
  • Ensure rapid ticket response and quick resolutions to issues.
  • Never saturate or over-provision servers to ensure stability and speed for our customers.
  • Use only high-quality enterprise-class hardware to ensure minimal downtime from hardware failures.
  • Provide clear pricing with no hidden fees or gotchas.
Subscribe to comment notifications
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments