Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Disable WP Cron and Set Up a Server Cron Job

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

WordPress runs scheduled tasks (like checking for updates, publishing scheduled posts, and sending emails) using its built-in pseudo-cron system, which triggers on page visits. This can slow down your site for visitors and cause tasks to run at unpredictable times. By disabling WP-Cron and setting up a real server cron job, you gain precise control over when tasks run, improving performance and reliability. This guide walks you through the process step by step.

What You'll Need

  • Access to your WordPress files (via FTP, cPanel File Manager, or SSH)
  • Ability to edit the wp-config.php file
  • Access to your hosting control panel or server terminal to create a cron job
  • Basic understanding of file editing and server commands

Step-by-Step

  1. Back up your site. Before making any changes, create a full backup of your WordPress files and database. This ensures you can restore if something goes wrong.
  2. Disable WP-Cron. Open your wp-config.php file (located in your WordPress root directory) and add the following line just before the /* That's all, stop editing! Happy publishing. */ comment:
    define('DISABLE_WP_CRON', true);
  3. Save and upload the file. If you edited locally, upload the modified wp-config.php back to your server, overwriting the original.
  4. Determine your server cron command. You need the absolute path to your WordPress installation. Common paths include /home/username/public_html or /var/www/html. You can find this by checking your hosting documentation or using an FTP client to see the full path.
  5. Create a server cron job. Access your hosting control panel (e.g., cPanel, Plesk) and look for the “Cron Jobs” section. If you have SSH access, you can edit your crontab with crontab -e.
  6. Add the cron command. The standard command is:
    wget -q -O - http://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
    Replace yourdomain.com with your actual domain. Alternatively, if you have SSH access, you can use:
    php /absolute/path/to/wp-cron.php
    Make sure to replace /absolute/path/to with the actual path from step 4.
  7. Set the schedule. Choose a frequency. For most sites, every 5 to 15 minutes is sufficient. In cPanel, you can set the minute field to */5 for every 5 minutes. In crontab, the line would look like:
    */5 * * * * wget -q -O - http://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
  8. Save the cron job. Confirm the cron job is saved. Some control panels require you to click “Add New Cron Job” or “Save”.
  9. Test that it works. You can check by temporarily adding a test to your WordPress site, such as a scheduled post. If it publishes on time, the cron job is functioning. Alternatively, you can check your server's cron logs if available.

Common Mistakes

  • Using the wrong path. If you use the php command, the path must be correct. A wrong path will silently fail. Double-check with your hosting provider.
  • Not disabling WP-Cron properly. If you forget to add the define line, WP-Cron will still run, and you may have duplicate tasks.
  • Setting the cron job too frequently. Running every minute can cause unnecessary server load. Stick to 5-15 minutes unless you have specific needs.
  • Using HTTP without authentication. If your site is behind a firewall or requires login, the cron job may not trigger. Usually, wp-cron.php is public, but if you have security plugins, you may need to whitelist the cron URL.
  • Forgetting to test after changes. Always test after making changes to ensure scheduled tasks still run.

Tips

  • Use a monitoring plugin. Plugins like WP Crontrol can help you see what tasks are scheduled and when they last ran, making it easier to verify your cron job is working.
  • Consider using a third-party cron service. If your hosting doesn't support cron jobs, you can use free services like EasyCron or cron-job.org to hit your wp-cron.php URL at intervals.
  • Set a reasonable interval. For most sites, every 5 minutes is fine. If you have heavy tasks (like backups), you may want to run them less frequently.
  • Keep your cron command simple. The wget command is widely supported and doesn't require PHP CLI. It's a safe choice for shared hosting.

Troubleshooting

  • Scheduled posts are not publishing. Check if the cron job is actually running. Look at your server's cron logs (if available) or add a temporary test like a PHP file that logs when it's accessed. Also verify that DISABLE_WP_CRON is set to true.
  • Emails are not being sent. If your site relies on wp-cron for email notifications, ensure the cron job is hitting the correct URL. Sometimes, security plugins block access to wp-cron.php; check your firewall or security plugin settings.
  • Cron job runs but nothing happens. This could be due to a plugin conflict or a PHP error. Enable WordPress debugging by adding define('WP_DEBUG', true); to wp-config.php and check the debug.log file for errors.
  • Getting 404 errors on wp-cron.php. This usually means the URL is incorrect or your server is blocking direct access. Try using the full URL with https:// if you have SSL. Also, ensure your domain resolves correctly.
  • Hosting provider blocks cron jobs. Some budget hosts disable cron jobs. If you can't create one, use a third-party service as mentioned in Tips.

Frequently Asked Questions

Why should I disable WP-Cron?

WP-Cron triggers on page visits, which can slow down your site for visitors and cause tasks to run unpredictably. A server cron job runs at fixed intervals, improving performance and reliability.

What is the default WP-Cron interval?

WP-Cron doesn't have a fixed interval; it runs whenever someone visits your site. This is why it's called “pseudo-cron.”

Can I use a cron job on shared hosting?

Yes, most shared hosting providers offer cron job functionality through cPanel or similar control panels. If not, you can use a third-party cron service.

What if I use a caching plugin?

Caching plugins can interfere with WP-Cron because they serve cached pages, reducing the number of visits that trigger tasks. Disabling WP-Cron and using a server cron job is even more important in that case.

Do I need to remove the define line if I switch hosts?

Yes, if your new host doesn't support cron jobs, you should remove the define('DISABLE_WP_CRON', true); line to re-enable WP-Cron, or set up a cron job on the new host.

Is it safe to disable WP-Cron?

Yes, as long as you have a working server cron job in place. Without it, scheduled tasks won't run at all, which can break time-sensitive features like scheduled posts.