in

How to View and Control WordPress Cron Jobs?

How to View and Control WordPress Cron Jobs?

Being on schedule is necessary to grow in any field, and that certainly includes websites as well. Some of the website owners use different Cron tools to automate some of the basic tasks. If you are using WordPress, then you should know that there is an inbuilt Cron that runs scheduled tasks automatically. Those functions could be anything depending on the user and the scheduled functionalities. Some of the beginner WordPress users are unaware of these Cron jobs, and they leave them unchecked. However, they might also be uninformed of the benefits of controlling croon jobs.

The foremost reason for managing Cron jobs is that they can significantly increase the speed of your site and assists you in making your site better. As this feature is enabled by default on a WordPress site, it is used by numerous plugins for backups, updates, handling comments, cache, and other similar actions. These plugins work on all the pages which means that every page is also using the Cron jobs. However, some of the pages or posts do not need these features, but the plugins are still using it and as a result, it slowdowns your website. You can increase the speed of your site by following the below-mentioned process to control the Cron jobs.

Step 1

To manage the Cron jobs, the first thing you need to do is install and activate the WP Crontrol plugin on your website. All you have to do is log in to your WordPress admin dashboard and navigate to the Plugins > Add New page. Here search for the plugin and hit the Install Now button. Once the installation completes, you need to ensure that you click on the activation link.

Step 2

Once you have activated the plugin, you need to head back to the WordPress admin dashboard and visit the Tools> Cron Events page. This page will show you all the Cron jobs running on your site including the default and the plugin ones. To edit a plugin Cron job, you need to identify its Cron job first. Most of the default Cron jobs start like wp_cron_job_name, so you can differentiate between a plugin and a default Cron job. Now, look out for the plugin’s Cron which you want to edit.

Step 3

Once you have found the desired Cron, you need to click on the Edit button which will take you to the Modify Cron Event page. Here you can see four different fields including hook name, arguments, next run, and event schedule. You are here to change the frequency of the Cron job, so you need to open the Event Schedule drop-down menu and select the desired schedule. You can choose from three different scheduling options; hourly, twice daily, and daily. After making all the changes, you need to hit the Modify Cron Event button to save all the changes.

Creating New Cron Jobs

Step 1

Not only editing an existing Cron job, but this plugin also allows you to create a new Cron job as well. Creating a Cron job is also an uncomplicated task. All you have to do is head over to the Tools> Cron Events page from the WordPress admin dashboard. Here you need to look for the Add Cron Event section which will have all the fields that were present in the Modify Cron Event section.

Step 2

Here the first thing that you need to enter is the hook name without any special characters or spaces. The next field will be of arguments where you need to specify the arguments if there are any, or else you can leave this field blank. Afterwards, you need to enter the Next Run which means that when the Cron should run. You can enter now, tomorrow, or a specific date. The last option will be of Event Schedule where you need to specify the frequency of the Cron job. Once you have entered all the necessary details, you need to click on the Add Cron Event button.

Add Cron Event

Step 3

You have now successfully added a new event to your Cron list, but the WordPress is still unaware of this job. To let WordPress know about this newly added Cron event, you need to add specific codes in the WordPress core files. The first thing you need to do is log in to your FTP client and head over to the WordPress core directory.

Step 4

Here you need to open the Themes> Your Current Theme folder and download the functions.php file on your local system. Now you need to open that file using any text editor and paste the following code into it.

if ( ! wp_next_scheduled( ‘wp_custom_cron’ ) ) {

wp_schedule_event( time(), ‘hourly’, ‘my_task_hook’ );

}

add_action( ‘wp_custom_cron’, ‘wp_custom_cron_func’ );

function wp_custom_cron_func() {

wp_mail( ‘youemailid@email.com’, ‘Automatic email’, ‘Automatic scheduled email from WordPress to test cron’);

}

Step 5

Now make the necessary changes in the coding like the hook name, schedule event, and your email address. Upon adding the code, you need to save the changes in the file and upload it back to your server. The WordPress will send you an email whenever this Cron job runs.

To manually test the Cron, you need to head back to the Tools> Cron Events page from the WordPress dashboard and look out for the newly created Cron Job. Upon finding, you need to click on the Run Now button to start it. You can now open the email specified in the coding to check the test email.

If you want to add a custom schedule for Cron jobs, then this plugin allows you to do that as well. Head over to the Settings> Cron Schedules from the admin dashboard where you can add custom intervals. You need to make sure that you enter the value in seconds only. After adding the values, you need to hit the Add Cron Schedule button to add the schedule.

WP Crontrol Custom Schedule

Endnote

This was the complete process of managing the WordPress Cron jobs. With this method, you can add, remove and edit Cron jobs. However, it is advised that you do not edit any of the Cron if you are unsure about its functionalities.

Leave a Reply

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

How to Add Autocomplete for Address Fields in WordPress?

How to Add Autocomplete for Address Fields in WordPress?

How to Automatically Add Watermark to Images in WordPress?

How to Automatically Add Watermark to Images in WordPress?