WordPress Cron and How to Control It

Cron Jobs or Cron is a system which allows you to schedule a task or event to be performed at a fixed interval of your choice (every day, hour or minute). For a WordPress website for example, a cron is useful for scheduling a new post to be published at a date and time of your choice.

Most cron jobs have to be manually configured in your cPanel > Cron Jobs page but if you run a WordPress website, WordPress runs their cron very differently. With WordPress, the cron is executed every time someone access a non-cached version of your website instead of at a fixed interval.

What is the problem?

As a result of the way the WordPress Cron (wp-cron.php) is designed, you can face two possible issues:-

  • If the cron runs too often, your website can experience performance issues or high CPU usage.
  • If the cron runs not often enough, some events or tasks may not run so your scheduled post may not be published.

What can be done about it?

You can control the problem by disabling the built-in WordPress Cron and instead create a real Cron Job in your cPanel.

Step #1: Disable WordPress Cron

Go to your cPanel File Manager, find and open up your wp-config.php file and add the following line right after the <?php line (it can be above or below the define( 'WP_CACHE', true ); line:

define('DISABLE_WP_CRON', true);

Step #2: Add a Cron Job in cPanel

Login to your cPanel, navigate to the Cron Jobs page and add a Cron Job to access the wp-cron.php page.

For the Common Settings, select Twice Per Hour (0,30 * * * *).

For the Command, input the following (replace yourdomain.com with your actual domain):

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

If you are running a WordPress Multisite setup, use the following Command instead:

cd public_html && /usr/local/bin/php /usr/local/bin/wp site list --field=url | xargs -i -n1 /usr/local/bin/php /usr/local/bin/wp cron event run --due-now --url="{}"

And you’re done! The WordPress Cron should now run automatically every 30 minutes instead of on every page load, thus saving you possible issues of it running too often or not often enough.