Skip to content

How to set up cronjob for WP Cron

About WP Cron

WordPress Cron (wp-cron.php) is the built-in task scheduler in WordPress, used to run scheduled tasks. Many plugins depend on WP Cron for their backend functions.

By default, WP Cron is triggered by website visits. Every time a visitor loads your site, there’s a small chance WP Cron will run and execute scheduled tasks. This approach has some downsides:

  • Website Speed: Running backend functions can slow down your site.
  • Server Resources: Checking the scheduled task list each time WP Cron is triggered consumes CPU cycles and memory.
  • Reliability: WP Cron depends on site visits, so if there are no visitors, tasks won’t be executed.
  • Timeliness: If you need tasks to run at specific times, it’s better to use a reliable cronjob service like FastCron.

To set up cronjobs for WP Cron, follow these instructions:

Disable WP-Cron

Open your wp-config.php file with a file manager (e.g. cPanel file manager) Go to the bottom of the database settings in wp-config.php, usually around line #37.

Add the code below:

define('DISABLE_WP_CRON', true);

then save the file.

Set up cronjob at FastCron

  • Log in to your FastCron account
  • Click Add a cronjob
  • Enter the URL to call
https://example.com/wp-cron.php?doing_wp_cron=1&__random__

(replace https://example.com/ with your actual WordPress homepage URL)

  • Select When to call: Every 5 minutes
  • Click Save.

And you’re done!

If you have some plugins that need to update frequently, just change the time interval to Every minute.

You may notice that I added ?__random__ to the cronjob URL. It’ll add a random string every time your cronjob is executed, preventing your web server from caching the HTTP request.

Some WordPress plugins rely on WP Cron to run their scheduled tasks. If you’re using one of these, set up a cronjob to run your website WP cron.