If you’re a WordPress developer or enthusiast, you’ve likely come across questions like “What is WordPress Cron?” or “How do I manage WordPress cron job?” Let’s break it down!
Cron is a UNIX-based utility that enables users to schedule tasks on a web server. WordPress takes this concept a step further with its own cron system, WP-Cron, which handles automated tasks such as checking for updates, publishing scheduled posts, and managing other repetitive processes.
Understanding how to set up and manage WP-Cron events can significantly simplify your website’s administrative tasks and enhance its functionality.
In this guide, we’ll walk you through setting up and managing WordPress cron jobs using two simple ways, ensuring you have the tools to automate your workflow easily. So, let’s get started.
Contents
ToggleUnderstanding WordPress Cron Job
Think of a WordPress cron job as your website’s personal assistant, handling repetitive tasks like checking for updates, publishing scheduled posts, or emptying the trash. These tasks are managed by WordPress’s built-in cron system, called WP-Cron.
Now, here’s the twist: while WordPress cron takes inspiration from the UNIX cron system, it doesn’t work exactly the same way. Instead of running at fixed times, WP-Cron schedules tasks based on intervals like hourly, twice daily, daily, or weekly. But there’s a catch — it only kicks in when someone visits your website.
Yep, that means if your site doesn’t get visitors, WP-Cron doesn’t run. This “on-page load” setup can sometimes be a bit unreliable, which is why many users opt for a more robust server-level cron job to keep things running smoothly.
Read: Learn WordPress Development: Tips for Beginners
What are the Benefits of WordPress Cron Job?
Setting up the WP-Cron system is super simple—no need to dive into complex UNIX commands like you would with traditional cron jobs. If you’re looking to automate tasks on your website or keep things like checks and verifications running smoothly, cron jobs are a great solution.
For example, you might want to ping a server daily, log system statuses every hour, or perform other recurring tasks effortlessly. One big advantage of WP-Cron is its flexibility. It uses intervals to schedule tasks, so even if a task doesn’t run at the exact time you set, it’ll still catch up and run eventually.
This is different from traditional cron jobs, which are more rigid—if a task misses its scheduled time, it won’t run until you reschedule it manually.
Learn: How to Fix “Briefly Unavailable for Scheduled Maintenance” in WordPress
Setting Up WordPress Cron Jobs Can Be Tricky. Need Help?
Our WordPress development experts can help you streamline your website’s functionality and automate tasks effectively.
How to Manage WordPress Cron Jobs: 2 Easy Ways
Now, there are plenty of ways to set up and manage WordPress cron jobs, but let me walk you through two of the most popular options.
- WP Crontol: This plugin makes it super easy to add, edit, and manage cron jobs right from your WordPress dashboard—no coding required! You can create new cron jobs, set up hooks and functions, and even customize the time intervals for your tasks.
- WP-CLI: This option is for those who love working with the command line WordPress CLI (WP-CLI). It’s a powerful tool for managing cron jobs and more, but it does require a bit more technical know-how.
Pick the method that suits your style best!
Manage WordPress Cron Jobs with WP Crontrol
Let’s walk through how to use the WP Crontrol plugin to view, manage, and add cron jobs for your WordPress site.
1. Install the WP Crontrol Plugin
First, install and activate the WP Crontrol plugin:
- Go to Plugins → Add New in your WordPress admin dashboard.
- Search for WP Crontrol and click Install Now.
- Once installed, click Activate.
To see the cron jobs running on your site, navigate to Tools → Cron Events in your dashboard.
Pro Tip: Don’t delete default WordPress cron jobs (they start with wp_). Removing them could mess up your site’s core functionality.
Add a New Cron Event
Now, let’s create a new cron job:
- In the Cron Events section, click Add New at the top of the page.
- Choose Standard cron event and create a unique hook name (use PHP naming conventions).
- Set the schedule time and recurrence (leave the Arguments field empty).
- Click Add Event to save it. You’ll see the new event in the cron jobs list.
3. Add Functionality to Your Cron Event
After creating the event, you need to define what it does:
- Open your functions.php file (located in your theme’s directory) using a file manager or an editor like cPanel’s File Manager.
- Add this code to define the action:
php
Copy code:
}
add_action( 'custom_cron_hook', 'custom_cron_function' );
function custom_cron_function() {
wp_mail( 'you@example.com', 'Scheduled Email,' 'This is a test email from your WordPress cron job.');
}
Replace you@example.com with your actual email address.
- Save the file and visit your site. If everything’s set up correctly, you’ll receive the test email.
Explore: Top cPanel Alternative Hosting Platform for WordPress and Others
4. Customize Cron Schedules
Want to use a custom time interval? Here’s how:
- Go to Settings → Cron Schedules in your dashboard.
- Under Add Cron Schedule, set your interval in seconds (e.g., 600 seconds for 10 minutes) and give it a name.
- Click Add Cron Schedule to save it.
5. Edit an Existing Cron Event
You can update existing cron events to use custom intervals:
- Go to Tools → Cron Events and find the event you want to edit.
- Click Edit, then change the recurrence to your new interval (e.g., 10 minutes).
- Click Update Event to save the changes.
That’s it! With WP Crontrol, you’ve got everything you need to easily manage cron jobs on your WordPress site—no coding expertise required!
Learn: How to Create an Event Management System in WordPress
Manage WordPress Cron Jobs with WP-CLI
If you’re comfortable using the command line, WP-CLI offers a powerful way to manage WordPress cron jobs. You can use any hosting solutions like Hostinger and Cloudways, which provide excellent hosting that makes using WP-CLI a breeze.
Let’s explore how you can manage cron jobs with WP-CLI:
Getting Started with WP-CLI
WP-CLI allows you to manage your WordPress site directly from a terminal interface, giving you more control over tasks like listing, adding, and managing cron events.
We are using Hostinger’s Managed WordPress hosting example here:
Hostinger’s Managed WordPress Hosting plans come with WP-CLI pre-installed. You’ll just need to connect to your hosting account via PuTTY SSH.
Steps to Access WP-CLI
- Open PuTTY SSH and connect to your hosting account.
Once connected, you can run the following command to list your WordPress cron events:
bash
Copy code:
wp-cron event list
- This will display all active cron events, showing details like the hook name, next scheduled run time, and recurrence.
To see a list of other WP-CLI commands, use:
bash
Copy code:
wp help
WP-CLI is perfect for those who want direct control over their WordPress site. Whether you’re using Hostinger’s pre-installed WP-CLI or accessing it through Cloudways, this method is efficient and ideal for advanced users.
If you’re not a fan of command-line interfaces, you can always use a plugin like WP Crontrol to manage cron jobs from your WordPress dashboard. Either way, you’ve got options tailored to your comfort and hosting provider!
Read More: Free WordPress Hosting Providers
How to Set Up a Real Cron Job?
Now that you understand what WordPress cron jobs are and how they work, you might wonder: What if I want to replace it with a real cron job? This is a great idea for specific scenarios like:
- Low-traffic sites where tasks need to run at precise times.
- Important tasks that shouldn’t depend on visitors triggering them.
- Mitigating issues like high page load times or DDoS attacks.
Let’s break it down step by step!
Step 1: Disable WP-Cron in Your wp-config.php File
First, you’ll need to disable WordPress’ built-in cron system so you can switch to a real cron job.
Here’s how:
- Open your wp-config.php file. Use an FTP client like FileZilla or an SSH client such as PuTTY to access your site files.
Add the following line of code just before the line that says /* That’s all. Stop editing! Happy blogging. */:
php
Copy code
define('DISABLE_WP_CRON', true);
This disables WordPress cron events, making it ready for a real cron job.
Step 2: Add a Real Cron Job to Your Server
Once WP-Cron is disabled, you can set up a real cron job. Here’s how to do it on the Cloudways platform:
- Log in to your Cloudways account.
- Navigate to Application Management → Cron Job Management → Advanced Section.
Add the following command, then click Save Changes:
bash
Copy code
*/5 * * * * wget -q -O - 'https://your-app-url.cloudwaysapps.com/wp-cron.php?doing_wp_cron' >/dev/null 2>&1
- The */5 * * * * part schedules the cron job to run every 5 minutes.
- Replace the placeholder URL (your-app-url.cloudwaysapps.com) with your actual application URL.
Here’s a Tip: If you’re unsure about time interval expressions, use an online cron schedule generator to get it right.
Also read about: A Simple Guide to Enable, Disable, or Limit WordPress Post Revisions
Conclusion
That’s It! You’ve successfully added a real cron job to your server. With this setup, your WordPress site will now handle scheduled tasks more reliably and efficiently, especially for critical processes.
WordPress cron jobs are a handy way to schedule tasks at custom intervals, making administrative tasks much easier to manage. While WP-Cron has its limitations, understanding how it works gives you the tools to streamline your site’s operations.
We hope this guide has helped you get a clear picture of WordPress cron jobs and how to set them up using plugins or WP-CLI.