Controlling WordPress Cron jobs does not have to be a nightmare

An average WordPress user doesn’t have a clue what are WordPress Cron jobs. That’s ok. If you include yourself in the statistics, don’t worry because you really don’t have to know anything about it to run a successful blog.

But since you’re already here, take a few minutes of your precious time and get to know WordPress just a little bit better. In this article, we are about to briefly show you what WordPress Cron jobs are and how you can speed up your WordPress site by controlling them. Now that we mentioned speeding up a site, WordPress Cron jobs sound much more attractive, right?

What are WordPress Cron jobs?

Cron is a computer software specifically built to help administrators to schedule different tasks on their servers. The software is usually to be found in Unix-like machines, and admins use it on an everyday basis. Although the name is same, WordPress Cron jobs behave a little bit different.

Unlike those system Cron jobs that work on specific times, WordPress Cron jobs rely on time intervals and actually simulate what the actual system Cron software does. WP-Cron runs only once users loads a page, what’s different than the system one that runs continuously. But we’re not going into details; if you are interested in how WordPress Cron jobs work, how to add custom intervals and deal with hooks, please see more in the WordPress Plugin Handbook.

Why WordPress needs Cron jobs?

Now that you know that WP-Cron is used for scheduling specific tasks, you can guess at least a few occasions when WordPress needs the service. WordPress Cron jobs include:

  • Checking for updates
  • Publishing scheduled posts
  • Deleting trash
  • Sending emails
  • Clearing drafts

Since WP-Cron is available to plugins as well, different themes and plugins will use it for specific tasks. So, for example, if you are using backup plugins for automated backups, that plugin will add a Cron job to know when it’s time to create a new backup of your system.

As you can guess, the more plugins you have, the more WordPress Cron jobs will end up on the list. And since WP-Cron is activated on each page load, that can really slow down your website once you hit a higher number of visitors. So, let’s see how to control WordPress Cron jobs without touching the code.

Control Cron jobs with WP Crontrol

No, that’s not a typo – the developers were really creative with the name, but that’s the least important thing about this plugin. What should interest you are the features that allow every WordPress user to control Cron jobs directly from the dashboard.

Control Cron jobs with WP Crontrol

With more than 50,000 active installs, WP Crontrol is the most popular one when it comes to controlling WordPress Cron jobs. As it’s entirely free, it would be a shame not to give it a chance.

Once you install the plugin, you will be able to view all Cron events. You’ll get to edit, delete and run any Cron event simply by clicking a button. If you want more, you can even add new events and customize them in details.

How to edit a Cron event

By navigating to Tools -> Cron Events, you will get a list of all events that are scheduled to run on your site. You will see hook names, scheduled times and intervals.

For starters, WP Crontrol allows you to run any given task instantly. So, for example, you can find a standard WP hook that checks for new theme updates: wp_update_themes. This one runs every 12 hours. If you want WordPress to check for new theme updates now, simply click a “Run now” link next to it. Although this might come in handy to actually activate a specific function before its schedule (for example, if you’re doing maintenance, you might want to delete trash right away), the main purpose is troubleshooting. Now you can easily run that specific function a few times in a row to see how it affects the performance of your website.

If you click on the “Edit” link, you will be able to customize the behavior of that particular Cron event. In this case, if you find a resource-sensitive Cron job that might slow down your site, you can easily change the recurrence interval. If a job has been scheduled to run once hourly, now you get to easily change that and tell WordPress to run it daily, for example. You can even add custom intervals, but we’ll talk about that just a few scrolls below.

Luckily, the developers haven’t included an option to delete any of the default WordPress Cron jobs so you can’t make a big mistake here. But since you can delete all the jobs created by the plugins, be careful if you decide to do so. If you’re not sure what you’re doing, it’s better to leave things as is or consult a WordPress professional who will advise you on the particular Cron job.

Add custom intervals

WP Crontrol custom schedule

If none of the intervals aren’t right for you, WP Crontrol allows you to add your own ones. Simply go to Settings -> Cron Schedules where you will be able to add new intervals in seconds. Don’t forget to write a custom name so that you can easily recognize new interval from the list.

If you just need to add a custom interval manually, you can do that even without the plugin. In that case, you’ll need the following code:

add_filter( 'cron_schedules', 'example_add_cron_interval' );

function example_add_cron_interval( $schedules ) {
$schedules['five_seconds'] = array(
'interval' => 5,
'display' => esc_html__( 'Every Five Seconds' ),
);

return $schedules;
}

How to add your own Cron event

Another great part of the plugin is that it lets you easily add your own Cron jobs. There are two simple steps to creating a custom Cron event:

  1. Go to Tools -> Cron Events and enter the name of hook
  2. Open functions.php file and add PHP code. For example:
add_action( 'my_hookname', 'my_function' );`

function my_function() {
wp_mail( 'hello@example.com', 'WP Crontrol', 'WP Crontrol rocks!' );
}

If you follow the example, WP Crontrol will tell WordPress to send an email to hello@example.com at time/intervals you selected. If you want to test it, hit the “Run now” button.


That’s it! As you can see, the plugin is relatively simple to understand, and you can finally control WordPress Cron jobs just by selecting them. Obviously, if you’re about to create custom ones, you will need a little bit more patience, and somewhat understanding of PHP and how WordPress hooks and functions work.

We hope that after this article you have a clearer picture of Cron jobs and that WP Crontrol will help you manage events and eventually speed up your site.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

One thought on “Controlling WordPress Cron jobs does not have to be a nightmare

  1. Wow! Finally I got a blog from where I be able to inn fact take helpful fats
    concerning my sgudy and knowledge.

Leave a Reply

Your email address will not be published. Required fields are marked *