Ins and Outs of WordPress Cron Jobs – How to View and Control

  • Home
  • Wordpress
  • Ins and Outs of WordPress Cron Jobs – How to View and Control
WordPress-cron-jobs-view-and-control

One of our readers recently inquired about the ab

ility to examine and operate the WordPress cron jobs system from the dashboard. Cron is a technology that allows you to conduct scheduled operations on your webserver.

WordPress includes a built-in cron that allows it to conduct scheduled operations like checking for changes, publishing scheduled content, and so on. This post will demonstrate how to see and handle WordPress cron tasks.

What Exactly WordPress Cron Jobs Are and How Does it Work?

The term cron refers to commands that run on a scheduled basis or at regular intervals. Web servers generally use cron to run scheduled tasks and maintain their systems.

WordPress is equipped with a cron system that allows it to schedule tasks. You can, for instance, check for updates, or delete old comments from your trash.

This is also how plugins can perform tasks that you specify.

For instance, by using WordPress cron, your WordPress backup plugin can generate backups automatically on a scheduled basis.

In some cases, plugins can use WordPress cron in an improper manner, resulting in slow website performance. This is especially common for those who host their website on a shared server.

There is a need to identify and fix the problem if a plugin performs resource-intensive tasks on a frequent basis.

Here’s how to access and command the WordPress cron jobs without writing any code.

WordPress Cron System – Viewing and Controlling

Start by installing and activating the WP Control plugin. You can find more information on how to install a plugin by reading our guide.

Immediately after activation, you must navigate to the Tools > Cron Events page to edit cron settings.

wordpress-cron-jobs-list

Using the WordPress cron jobs system, you’ll see the list of cron events that are scheduled to run on your site.

There is a first column that lists the name of the hook that runs the cron job.

A hook’s name usually gives you an idea of what it does.

Wp_update_plugins, wp_update_themes, and other default hooks begin with the wp_ prefix.

N.B: It is extremely important to keep cron events in mind and never remove a WordPress cron jobs event.

Now let’s say a WordPress plugin is removing resource-intensive content through a cron event.

The first thing you need to do is check the plugin’s settings to see if there is a way to control it there. If there isn’t, you can edit the cron by clicking on the ‘Edit’ link next to the event.

wpcronedit

When you click on the Edit button, the ‘Modify cron event’ tab will open.

This is where you can modify how often the event runs.

modifycronsettings

Click Save Changes when you are finished to save your settings.

WordPress Cron Events – Adding Your Own

Adding your own cron jobs to WordPress is easy with the WP Control plugin. In the Tools > Cron Events page, scroll down to the ‘Add Cron Event‘ tab.

addcronevent

Here you need to enter the name of your cron event hook. Hook names cannot have spaces or special characters.

The function you’d like to execute will require arguments. If those arguments aren’t provided, then you’ll need to provide them.

Next, WordPress needs to know when to run the cron again. A cron will be triggered immediately if you enter ‘now‘, or tomorrow if you enter ‘+2 days’, or 25-02-2020 12:34:00 if you enter ‘tomorrow.’

Last but not least, you need to select a schedule. Depending on your needs, you can choose from hourly, twice daily, daily, or once a week. A non-repeating schedule is also an option.

After completing the steps, click the Add Cron Event button to save your changes.

You will now see your cron event listed in the events list.

As of now, WordPress does nothing when this event triggers because you haven’t told it what to do.

So, add your hook and a function that runs so that the corn hook is triggered. Here’s the function below-

add_action( 'wpb_custom_cron', 'wpb_custom_cron_func' );

function wpb_custom_cron_func() {
wp_mail( '[email protected]', 'Automatic email', 'Automatic scheduled
email from WordPress to test cron');
}

Once the cron starts, this function just forwards you a test email. You can now verify your scheduled event by scrolling up the screen and clicking the ‘Run Now‘ option next to it.

N.B: Note that using cron demands basic coding and WordPress development abilities.

Finally, Insights

We’ve reached the conclusion of our post, and perhaps, you’ve learned something new. Follow the above instructions and you’ll get all the information about WordPress cron jobs.

You may also want to see our guide on how to unpublish a WordPress page, also give this a shot as well to know how to uninstall and delete the WordPress theme.

If you have any questions or are confused about the procedures, please leave them in the comments area.

Please subscribe to our WordPress video tutorials on YouTube if you enjoyed this content. We may also be found on TwitterFacebook, and LinkedIn.

  • 673 Views
  • Comments are closed