Get started with 33% off your first certification using code: 33OFFNEW

How to ensure WP Cron always runs in WordPress

2 min read
Published on 21st November 2023
How to ensure WP Cron always runs in WordPress

In the world of WordPress, WP Cron plays a vital role in handling time-based tasks like publishing scheduled posts, checking for updates, and running automated backups. However, WP Cron is not a real cron job; it's a pseudo-cron system that depends on site traffic to trigger events. This dependency can lead to inconsistent behavior, especially for low-traffic sites. Let's explore how you can ensure your WP Cron jobs always run as expected.

Understanding WP Cron

WP Cron is triggered whenever someone visits your WordPress site. If there are no visitors, scheduled tasks may not execute on time. This system works well for sites with regular traffic but can cause issues for those with fewer visitors.

Method 1: Replace WP Cron with a Real Cron Job

One of the most reliable ways to handle WP Cron tasks is to replace them with a real cron job managed by your server.

  1. Disable WP Cron: First, you need to disable the default WP Cron. Add the following line to your wp-config.php file:
define('DISABLE_WP_CRON', true);
  1. Set Up Server Cron Job: Access your hosting account's cPanel or equivalent, and set up a cron job. The command should call the wp-cron.php file. For instance:
wget -q -O - https://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
Schedule it to run every five minutes, or as per your site's specific needs.

Method 2: Use a Cron Service

If you don't have access to server cron jobs, or prefer an easier solution, consider using a third-party cron service like EasyCron or SetCronJob. These services will hit your wp-cron.php file at regular intervals.

  1. Register with a Cron Service: Sign up for a cron service.
  2. Configure the Service: Set up a new cron job pointing to https://yourdomain.com/wp-cron.php. Configure the frequency according to your requirements.

Method 3: Optimize WP Cron for Low Traffic Sites

If the above methods aren't viable for you, there are ways to optimize WP Cron for low traffic sites:

  1. Cache Plugins: If you're using a caching plugin, ensure it doesn't cache the wp-cron.php file.
  2. Regular Traffic: Encourage regular traffic through social media, newsletters, and SEO, which can help trigger WP Cron naturally.

Testing Your WP Cron Configuration

After setting up your cron job, test to ensure it's working:

  1. WP Control Plugin: Install a plugin like WP Control to view and manage cron events.
  2. Check Scheduled Tasks: Schedule a post and see if it gets published as expected.