Cron Job – WordPress Solution – Speed Up WordPress website

Cron JobPageload SpeedWordPress
Cron Job – WordPress Solution – Speed Up WordPress website
Views: 2406 November 25, 2021

We usually encounter with Cron Job and most of the people don’t know how much it can impact Speed of WordPress website if you did wrong with Cronjobs.
In this blog we’ll discuss about how we can delete unwanted crons in correct manner from WordPress.

Speed Up WordPress website by Cron job removal

It made little difference for a small number of cron jobs that’s true but years into the life of a WordPress site one must bloated with hundreds if not thousands of old cron jobs from deleted plugins. Now, instead of suggesting to increase the php memory limit I would suggest that first check the number of cron jobs in wp_options when problem-solving fatal memory errors. It may be surprising if you find a lot of Cron Job.

Here is a step-by-step method for deleting thousands of old cron jobs that I would like to share with everyone.

  • Log into phpMyAdmin
  • Select the used database and then the ‘search’ tab.
  • Type ‘cron’ in search field then select ‘all tables’ and clicked ‘Go’.
  • Scroll down the search results list to my wp_options table.
  • Now, click ‘Browse’.
  • At the top of the list was option_name ‘cron’.
  • Click ‘Edit’ then wait for the page to load.
  • Now, click on the box that show the list of cron jobs.
  • The cron list was so long that it may take some time to respond.
  • Select all crons using Ctrl-A on the keyboard before hitting the delete button.
  • Again, It may take some time before browser complete the deletion

Will it delete Cron job for active plugins?

  • After another couple of minutes the cron jobs for current active plugins will re-populat the list.
  • Also hundreds from common plugins such as Wordfence, BackupBuddy, Nextgen Gallery, and AutoOptimizer – all of which we generally use and if not useful then un-install as well.
  • It should do the trick and your website now will loads like it’s been turbo-charged.

It will load the admin area much quicker. Admin timeout errors have disappeared.

What if I want it to fix via DB commands?

First log into your database and then enter

SELECT * FROM `wp_options` WHERE option_name = 'cron'

If you find it you might try:

In SQL: UPDATE wp_options SET option_value = '' WHERE option_name = 'cron'
In wordpress: update_option('cron', '');

You might need to either delete the cron option or set the value to an empty serialized array.

Using update_option would be safer as value should be a serialized empty array or an empty string. You could check in wp-includes/options.php though … but using update_option will handle it properly without worrying about the database.

Do it using WP-CLI

WordPress cron events can also be cleared from the command line, using WP-CLI

wp cron event list
wp cron event delete your_example_event

More details in the wp-cli docs.

wp option delete cron works when there are thousands of cron jobs stuffed in the options. These bad jobs comes mostly from bad plugins, doing cron the wrong way.

One more way we can do this

An even simpler solution is to call delete_option( ‘cron’ ); once in some plugin. All automatically added cron jobs will get added again on the next visit/request of your site.

As a one case (mu) plugin that only runs whenever you activate it:

<?php
/** Plugin Name: Clean Cron */
register_activation_hook( __FILE__, function()
{
delete_option( 'cron' );
} );
More Categories
Cron JobInternet MarketingLogin SecurityOnline MarketingPageload SpeedShopifySitemapSocial Media MarketingWeb DevelopmentWordPress