WordPress Code Snippets

A fresh mix of code snippets and tutorials

WordPress Cron Not Working

271

Some servers disable the functionality that enables WordPress Cron to work properly. This post provides an easy fix that should work on any server.

Problem

My WordPress plugins, SFS and SAC, can do some cool stuff with WP Cron. But sadly on media temple servers WordPress Cron is not working. So after doing some research, it turns out to be a relatively common problem: various web hosts disable the functionality that is required for WordPress Cron to work. It’s kind of a bummer, but there is a relatively simple solution.

Solution

So if WordPress Cron is not working on your server, you can either switch hosts (if that is a luxury you can afford), or you can try the following quick fix.

Step 1: Add the following line to your wp-config.php file:

define('ALTERNATE_WP_CRON', true);

That’s all there is to it. This line invokes WP’s alternate cron method, which seems to work well on any server. So just add the line of code right above the line in wp-config.php that says, “That’s all, stop editing! Happy blogging”, and you’re done. Enjoy your bowl of WP Cron.

Downside & Alternate Solutions

The downside is that every so often, the requested URL will include a long query string containing various wp-cron parameters. If you surf around this site, for example, eventually one of the URLs that you visit will look something like this (note: because of googlebot’s aggressive crawl behavior, the domain name has been changed for the following example):

https://example.com/?doing_wp_cron=1234567890.09876543210987654321

Not really that big of a deal, depending on how frequently WP Cron is running on your site. But if the occasional weird looking URLs are a deal-breaker for you, you alternately could rent a cheap server and set up a cron job, or even use a free cron service, which could fit the bill depending on your needs.

Bonus tip: you can trigger WP Cron manually by visiting the following URL:

https://wp-mix.com/wp/wp-cron.php?setcronjob

Happy cron’ing people.

Related Stuff

Learn more

WordPress Themes In Depth


Show Support

Like our new Facebook Page to show support!