We don’t often think about WordPress cron jobs. They occur in the background periodically, and the only time the average user needs to worry about them is when something goes wrong. It’s only when something goes wrong that most WordPress users even become aware of something called “cron.” But for those who already know what cron is, here’s how to debug and clean up your cron queue easily using a simple plugin.
Errors in Cron
Because of the frequency with which cron runs and the resources, it can consume, I recommend disabling cron on WordPress and setting it up to run manually to control the frequency and prevent scripts from potentially running dozens of times a day when they only need to do so once. I’ve configured my server to send me error notifications, and a while back, I started getting these for my site WP-Tweaks.com:
This is the HTML output of a standard WordPress error page. I copied all the contents, pasted them into a file called “test.html,” and opened it in my browser to see what it was about. Just a regular WordPress error generated by the script named in the first few lines of the e-mail.
To debug, I had to better understand what was happening inside cron and which hooks it was calling.
WP Crontrol to the Rescue
The tool best suited to the problem is a WordPress plugin called WP Crontrol. After downloading and installing the plugin, you can access all your cron events in WordPress by clicking “Settings” from the plugin page, as shown here:
In the next screen, you can see a list of hooks that run in wp-cron.php:
Each of these hooks corresponds to a specific “Action” in the WordPress PHP files – either the functions.php or elsewhere. Unfortunately, the plugin doesn’t tell you which file contains the script. But if there’s an error message, it should give the script name and the line number.
As you can see above, some of these hooks have no action. Removing them should be perfectly safe by clicking the “Delete” link.
Using WP Crontrol, you can change the schedule for each cron hook by assigning them an entry from the predefined “schedule” dropdown box in the edit screen or create an entirely new schedule.
Plugins that Don’t Clean up Behind Themselves
A major source of useless entries in WP Cron is deactivated or deleted plugins that didn’t do a good job of cleaning up after themselves. Another equally annoying source is plugins that no longer use a certain hook but leave it in Cron. Yoast SEO is a culprit in this regard, an example being the outdated wpseo-reindex-links hook with no action. Feel free to remove these and clear up your WordPress cron queue.
Getting Rid of the Cron Output
If you rather you didn’t hear from the WordPress cron system altogether, then I suggest you disable the output entirely. The best way to do this is to add the following after your manual cron command:
> /dev/null 2>&1
For example, I run WordPress cron by calling the wp-cron.php manually from my server’s cron queue using the “php” command. If I wanted to suppress the output, I would use this:
php https://[path to wp-cron.php] > /dev/null 2>&1
Save the changes, and you’re done.
Periodically Check WordPress Cron
Cleaning up your WordPress cron queue is good hygiene practice. Think of it as spring cleaning your WordPress installation, along with deleting old revision posts and outdated entries from wp_options. Make a note on your calendar to perform all these tasks once every few months, and you will have a happy WordPress installation!
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!
Leave a Reply