WP cron is one of the greatest features of WordPress. However, it’s irritating when your site is low traffic, or for whatever reason, wp cron refuses to work properly. You can’t schedule your postings or newsletter digests, social media re-posts, WAF scanning, etc. And if your plan is to get serious about your personal blog or you’re a professional blogger or it happens to manage a multi-author blog/website, then this thing can be very annoying.
For the record, wp cron get triggered on every page load and during that page load.
We’re going to use a solid Linux Cron Job instead of WordPress in order to force WordPress do the “job” no matter what. In my case, I use a cron job running every minute to make sure my scheduled posts will be published on time or with max 30 seconds latency.
Disable built-in WordPress Cron
First, we should disable wp cron since we’re about to run it via our system’s task scheduler. There’s no reason to waste resources, especially if we run a very busy website.
wp-config.php and add the line below:
Define Linux Cron Job
To trigger WordPress cron we just need a single http request to
wp-cron.php file, with a parameter named
doing_wp_cron. You can use
wget or curl to do the same thing. I prefer wget for such things.
We’re need to specify an existing user agent (-U parameter) for our requests such as
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0″ “http://www.gnu.org/software/wget/ to avoid getting blocked by apache’s mod security block rules and
-o set to
/dev/null in order not to save any responses.
If the target website is served via SSL protocol and the certificate is self-signed, we need to use the extra parameter
--no-check-certificate to tell wget not to check certificate’s validity. Our target URL is
example.com/wp-cron.php?doing_wp_cron and last but not least we need to add
> /dev/null 2>&1 at the end of our cron command to redirect any output to
Our command should like this:
wget -U "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0" "http://www.gnu.org/software/wget/" -O /dev/null http://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
Set up UNIX cron job via crontab
First, login to your server via ssh, type crontab -e (if you’re doing it for the first time you will be prompted to choose your favorite text editor) and add the following line
* * * * * wget -U "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0" "http://www.gnu.org/software/wget/" -O /dev/null https://powerpolitics.eu/wp-cron.php?doing_wp_cron > /dev/null 2>&1
Write and Exit nano.
For those who are using virtualmin hosting panel you’ll need to search for “Scheduled Commands” and replace with your own values accordingly to the image shown below.
Websites & Domains → Scheduled Tasks → Add Task:
Task type: Fetch a URL
Now, on the “Run” field, choose “Cron style” and put
* * * * * on the input field as Plesk’s built-in scheduling options lets you run a command up to hourly basis. For more information about cron syntax read here
Write a descriptive name about your wp cron job and choose Do not notify at Notify settings section.