fbpx

How can we help?

Cron Job

“Cron Job is a time-based job scheduler.” It is a system that enables users to implement commands, programs, and other actions at a particular time.

Basically in an era where a customer has a lot of options to choose from, it becomes necessary that a brand keeps up with its presence, Hence, the recalling feature should definitely be on your priority list.

Why Cron job?

Cron Job is a system that schedules an action to take place at a specific time in the future without actually having someone to perform it. Hence, it runs on an automated form.

In order to automate, Word press uses a file known as wp-cron.php as a virtual cron job, for performing tasks such as,

  • Executing those that occur at a regular interval;
  • Executing those that occur once at a fixed time.

Examples of tasks occurring at a regular interval:

  • Website Backup.
  • Ensuring WordPress is in it’s latest version.
  • Ensuring plugins and themes are up to date.
  • Database optimization for performance improvement.

Examples of tasks occurring at a fixed time.

  • Posting a blog post at a particular time,
  • Email outburst at a specific time.

WordPress cron system without code can be configured and operated. Let us explore how!

The first thing we need to do is install and activate the WP Control plugin.

  • Log in to the Admin Panel.
  • Go to WP Admin >> Plugins >> Add new. Find for Wp Control or directly download from here.
    wp event manager Cron Job 1
  • Install the plugin.
  • After the plugin is installed and activated, Go to Installed plugin menu and find for the WP control plugin and click on Cron Event.
    wp event manager Cron Job 2
  • Find your schedule actions in the Cron events section of the tools list.
    wp event manager Cron Job 3

Add Cron Events in WordPress

In order to add cron jobs to WordPress one needs to go to Tools » Cron Events page and scroll down to the ‘Add Cron Event’ tab.

You can now customize your own cron event in WordPress:

  • Provide a hook name for your cron event.
  • Provide arguments, if the function you want to execute requires it.
  • Next, inform WordPress when to run the cron next time. You can enter ‘now’, ‘tomorrow’, ‘+4 days’, or specific date, ’25-02-2020 12:34:00′.
  • Lastly, select the schedule. It may be hourly, thrice daily, daily, or once a week. You can also make it a non-repeating event.
  • Next, save the changes by clicking on the Add Cron Event button.
  • The cron event will now appear in the events schedule list.
  • However, the task does not end here as we haven’t told WordPress what to do when this event is triggered.
  • Therefore, add your hook and function that runs when the cron hook is triggered.
    <?php
    
        add_action( 'wpb_custom_cron', 'wpb_custom_cron_func' );
     
          function wpb_custom_cron_func() {
          wp_mail( 'you@example.com', 'Automatic email', 'Automatic scheduled email from WordPress to test cron');
          }
    ?>
    
  • Test the function now!
Tags:
Was this article helpful?
How can we improve this article?
Quick Links