How to manage WordPress Cron with WP Crontrol Plugin

By on April 18th, 2022

Many WordPress beginners have a common question “what is a cron job and how to set up the cron job for the site?” don’t worry. This article will cover all your questions with a detailed outline.

First, let’s check what WordPress cron is? And how does it work?

What is WordPress Cron? How does it work?

Wp-Cron is the feature that executes WordPress scheduled tasks of your application. For example, editing or deleting the comments, checking for regular updates, scheduling a post for publishing, etc. 

By default, WordPress provides a weekly, daily, twice daily, and hourly based time interval for executing tasks. Jobs are executed only when site visitors come to visit your site or while page or while the page is loaded.

You can manage WP-Cron using many different ways. Here we will discuss an easy way to manage the WordPress Cron with the help of the plugin called WP Crontrol

WP Crontrol is the best cron job setup plugin for WordPress, with over 200,000 active installations. It allows you to add, manage, and modify WordPress cron jobs directly from the admin side. 

The plugin is aware of the timezone, and it will also send you a warning message if the cron system doesn’t appear to be working.

So, let’s get started by installing the plugin.

Install and Activate the Plugin

Install the plugin just like another one by navigating Plugins on the WordPress dashboard and searching WP Crontrol on the search bar. You’ll see the plugin like the image below. Install and activate it.

Upon activation, you will notice that a new option called “Cron Events” has appeared under the tools tab.

Understand Cron Events

By visiting the option mentioned above, you’ll see a list of all cron events scheduled to run on your WordPress site using the WP-Cron system.  

Each hook is the event run by the WP-Cron system. Most of the hooks, by default, are starting with wp_prefix like wp_https_detections, wp_version_check, etc.

Here you can see that the first column is the hook used by WordPress core or any plugin. Notice that you can’t delete the hook whose prefix starts with WP because it’s a Cron of WordPress core. However, you can use Edit or Run Now options.

The next column, Argument, contains the arguments passed to the hook function. The Next Run column shows you when the next hook will run with a specific date and time.

The Action column shows you what action the hook will perform when it runs. For example, “wp_version_check( )” function runs to check the current version of WordPress.

And the last column, Recurrence, defines the scheduled time of the cron jobs. In short, it is the time interval for the particular scheduled tasks.

Edit Cron Events

You can edit the job by clicking on the Edit link located under the specific hook. Here, for example, I edited the “wp_https_detection” hook. 

As you can see in the above image, you can change the hook name, add an Argument, edit the next run time, and change the Recurrence time of the hook.

Add Cron Schedule

For adding your custom Cron schedule, navigate Settings >> Cron Schedules to add a new cron schedule that will allow you to schedule events that re-occur at the given interval. Mainly, four default Cron Schedules are added: hourly, twice daily, daily, and weekly. 

After adding Internal Name, Interval, and Display Name on the appropriate field, you can now replace it with your own custom interval like the following image.

Adding a New Cron Event

Adding a simple task for your cron is easy, but what if you want to add your cron for the application. Don’t worry. Just follow the instructions given below.

First, go to the Cron Events tab and click on the Add new cron event button; you can see the screen like the following image.

First, select the type of event(Standard cron event or PHP cron event), then give any hook name you want. Note that the Hook name can not have a space or unique character Next field is the Argument field that you need to add in a JSON encoded array. This field is optional, so you can skip it if you want.

You can select the Next Run time when you run the hook in the upcoming time. You can choose a specific date with an accurate time. For example, you can run the event on any upcoming date and time, like at 11 hours 45 minutes 5 seconds. At last, select a recurrence time like we discussed before and click on the Add Event button. Your cron event will now appear on the event list. 

Currently, the newly created event can’t perform any action because you can’t tell WordPress what to do when this event is triggered. For that, you need to add the function and a hook name of the event.

Add _action(  ‘interserver_new_cron’‘interserver_function’ );
Function interserver_function() {
    wp_mail( ‘youremail@example.com’, ‘ Interserver_cron’, ‘ website and domain hosting service provider’ );
}

Remember to add your own email address in the above code.

You can add the above code directly from the WordPress dashboard or edit it via an FTP client like FileZilla. Once you are done, go to the cron events and click on the Run Now link under the cron event you added.

Conclusion

WP Crontrol enables you to control the WP-Cron system, so you can add, delete, edit or run any cron event you want. You can view all cron events along with their argument, actions, recurrence, and when the next due of the cron. The plugin is trusted by more than 200,000 users worldwide and so on.

That’s it. We hope this article might help you understand the plugin and its features better.

Leave a Reply