How to enable & Configure WP-Cron

Boost CSV Import Performance

Parallel processing is one of the ways to get things done at a faster pace. WP Ultimate CSV Importer has been released with faster import performance. The featured images from external URLs are uploaded together with the help of Cron in the background to make the import faster. In this article, you will learn how to enable WP Cron. Also, you will learn the configuration of wp-cron, optimized for improved performance.

WP-CRON, or WordPress Cron, acts as a virtual cron system within WordPress. Unlike traditional cron jobs that run at the server level, WP-CRON relies on visitor requests to trigger scheduled events. While this approach simplifies setup, configuring it correctly is crucial to prevent potential issues and ensure reliable automation.

WP-Cron is a pseudo-cron system implemented in WordPress for scheduling tasks and events. It’s used to automate various background processes such as publishing scheduled posts, checking for updates, sending email notifications, and executing plugins’ scheduled tasks.

Cron jobs in WordPress are stored in the WordPress database. They are managed by the WP-Cron system and are typically registered by plugins or themes to execute specific tasks or events at scheduled intervals.

Is WordPress Cron enabled?- How to enable WordPress cron?

By default, the wp-cron is enabled because there are WordPress features that rely on to execute scheduled jobs. In case Cron is disabled, you can also enable WP-Cron WordPress by editing the wp-config.php file in your WordPress root folder and adding the following line to the file.

define(‘DISABLE_WP_CRON’, false);

If it is found true, change it to false to enable WP-CRON.

 

Verify in the WordPress Dashboard

Navigate to your WordPress Dashboard. Go to Settings > General. Ensure the “Timezone” setting is correctly configured.

Hooking WP Cron in the task scheduler

WP Cron doesn’t run continuously and to run the tasks at the time of import, you can set up the system task scheduler to run on the intervals. If you also have a high-traffic website you can trigger the WP-Cron only at the time of your CSV import.

 

Windows

In Windows, you can schedule the tasks in Task Scheduler. All Programs → Accessories → System Tools → Task Scheduler.

 

Cron entry in Windows 1

You can trigger the Cron to execute in several different ways, one of the methods is to use PowerShell via cmd.exe.

powershell“Invoke-WebRequest

Mac/Linux

Both Mac OS and Linux use Cron as a time-based scheduling system. You can simply execute via the terminal.

Users-MacBook-Pro:~ user$crontab -e

If you want to run regardless of the time sections, you can mention with Asterisk(*)

* * * * * wget http://Your_Site_URL/wp-cron.php

If you need to run your import every 2 hours regardless of the day or month, you need to specify like

* 2 * * * wget http://Your_Site_URL/wp-cron.php

Now you are completely done with your Cron setup and the featured image gets populated parallelly with your content import. The Cron entry setup differs for each hosting provider.

Cron Job Entry

WordPress cron job or WP cron not working

Sometimes, an error may occur, if the WP cron is not working. That is the WordPress cron jobs system is disabled. This means the garbage collection system will not work unless you run the cron system manually. If your WordPress site has the cron jobs system disabled, it can impact various scheduled tasks, including garbage collection. WordPress relies on cron jobs for tasks such as scheduled post publishing, plugin updates, and garbage collection, among others.

To run all the pending cron events

wp cron event run –all

Visit the Cron URL

WordPress has a built-in mechanism to trigger cron events when someone visits your site. You can manually visit the following URL in your browser

http://yoursite.com/wp-cron.php?doing_wp_cron

Here enter your actual domain name in the place of “yoursite.com”.

WP Ultimate CSV Importer Pro

WP Ultimate CSV Importer Pro

Get Ultimate CSV/XML Importer to import data on WordPress faster, quicker and safer.

Scheduled Task with Server Cron

You can set up a cron job in WordPress without a plugin by adding custom code to your theme’s functions.php file or by using a custom plugin. Alternatively, you can schedule cron jobs directly on your server’s control panel or through a command-line interface like SSH.

Set up a server cron job to run the WordPress cron regularly. Edit your server’s crontab file:

crontab -e

Add a line like the following to run the WordPress cron every 5 minutes:

*/5 * * * * wget -q -O – http://yoursite.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1

Replace “yoursite.com” with your actual domain.

After enabling the cron system, WordPress should be able to perform scheduled tasks, including garbage collection. Keep in mind that running the cron system too frequently may impact server performance, so adjust the frequency based on your site’s needs.

To re-enable the default cron behavior, remove any custom cron-related configurations and ensure that the Disable_WP_CRON constant in your wp-config. php file is not set to true. This constant, when set to true, disables the default cron behavior in WordPress.

If the external wp-cron seems to be enabled, you can still manually run it using the following methods:

To manually run the cron system in WordPress, you have a few options:

  1. Use WP-CLI

If you have command-line access to your server and WP-CLI installed, you can manually trigger the cron events. Open a terminal, navigate to your WordPress root directory, and run the following command:

wp cron event run –all

This command instructs WordPress to execute all pending cron events, ensuring timely updates and scheduled tasks.

  1. cURL or Wget

Alternatively, you can use cURL or Wget to make an HTTP request to the wp-cron.php file. This simulates a visitor accessing your site and triggers the cron events. Here’s an example using cURL:

curl http://yourdomain.com/wp-cron.php

Replace “yourdomain.com” with your actual domain. This method is useful if you don’t have access to WP-CLI.

Maximizing WordPress Automation: Top WP Cron Plugins and Management Tips

In the dynamic world of WordPress, automation is key to maintaining efficiency and staying ahead of the curve. One of the fundamental tools for automating tasks within a WordPress website is the Cron system. Cron jobs are scheduled tasks that execute at predefined intervals. In WordPress, the WP-Cron system handles these scheduled tasks, ensuring that maintenance activities, updates, and various other processes occur timely and seamlessly.

How to Setup and Manage WP-Cron using plugins?- Top WP Cron Plugins

However, managing WP Cron effectively requires attention to detail and sometimes additional plugins to enhance functionality. Let us explore some of the top WP Cron plugins available and their relation to CSV importer.

Below are some of the top WP Cron plugins available to enhance WP-Cron functionality.

  • WP Crontrol

WP- Crontrol plugin is one of the top most plugins to set up and manage Cron Jobs effectively in WordPress. It is a free plugin that offers a user-friendly interface to manage WP-Cron jobs. WP-Crontrol allows granular control over cron events, enabling you to add, edit, and delete events directly from the WordPress dashboard.

How does the WP- Crontrol works?

Step 1: Install and Activate 

  • Login to your WordPress dashboard and Install the WP-crontrol plugins.
  • Once installed, click on Activate.
Wp crontrol install and Activate

Step 2: Access the plugin

  • To access the WP-Crontrol plugin, navigate to Tools -> Cron Events
Wp crontrol access the

Step 3: WP- Crontrol dashboard

  • Once you access the extension, it will land on the WP- control dashboard. Here, you have a complete overview of all the WP cron jobs running on your WordPress site. 
  • It also includes the default wordpress cron jobs that prefix with wp. Make sure not to delete these core files as it will impact the core functionality of your WordPress site.
Wp crontrol wp default cron listed

Step 4: Add New Cron event

To add a new cron event, 

  • Navigate to the Add New button corresponding to the Cron events tab.
Wp crontrol Add new cron event
  • The Add new cron event page will be displayed.
  • Select the cron event type as the standard cron event 
  • Provide the name of your webhook with the php name convention. For example, smack_cron_event.
  • The Arguments field is optional. You can simply leave it empty or you can use your desired JSON-encoded array
  • Select the time for the next run as Now, tomorrow, or At(provide any specified date and time) to run the cron event next time.
  • Select the recurrence of the cron event from the drop-down. That is how often the cron events need to run. For example, every two hours, every ten minutes, etc.,
  • Finally, click on Add Event. Now new WP cron events have been added to your CRON event list.
wp crontrol add event
  • Here, you have the None option which shows an error. So you have to write the below code in functions.php.
Wp crontrol Action none
  • Navigate to the xampp/wamp in your local computer where you have installed your WordPress.
  • Navigate to the htdocs->wordpress->wp-content-> themes-> select your desired theme->functions.php file
wp crontrol functions
  • Open the file and write the below code:

add_action( ‘smack_cron_event’, ‘smack_cron_event_func’ );

function smack_cron_event_func() {

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

}

Wp crontrol Add code

Note: Make sure you have edited the above code by replacing smack_cron_event with your desired cron event name that you have created, and [email protected] with your email address.

Once done, you will receive an email at the email address mentioned in the code. The mail received indicates that the cron runs successfully.

Step 5: Add new CRON Schedule

WordPress allows four standard cron intervals to choose when creating a new cron event. However, with WP-Crontrol, you can also add new custom cron intervals by,

  • Navigating to WordPress Settings -> Cron Schedules or navigate to Tools-> Cron Events-> Cron Schedule
Wp crontrol Cron schedule
  • Provide the internal name for your cron schedule with php naming convention For example, smack_twenty_minutes.
  • Then provide the interval in seconds. Here, I have set 1200 seconds(20 minutes)
  • Provide the display name. Here, I have given 20 minutes.
  • Click on Add Cron schedule. The newly created cron schedule has been listed in the table.
Wp crontrol Adding new schedule

Step 6: Edit or delete any existing cron event

In addition to adding new cron events, WP Crontrol enables you to edit or delete existing cron events effortlessly. This functionality is useful for fine-tuning scheduled tasks or removing redundant cron jobs.

With WP- crontrol, it is easy to edit any existing WP- CRON event that was listed in the WP-crontrol dashboard.

Wp crontrol edit cron schedule
  • Hover over the desired Cron event and click on Edit. 
  • Edit the desired fields based on your business needs. You can update the recurrence time interval, Hooke name, or Next run time. 
  • Once edited, click on Update Event.
Wp crontrol edit cron event

To delete an existing cron event, hover over the desired cron event and click on Delete.

WP Crontrol is a valuable tool for WordPress site administrators and developers looking to manage cron jobs effectively. By providing an intuitive interface and robust features, WP Crontrol simplifies the process of scheduling, monitoring, and debugging cron events, ultimately enhancing the automation capabilities of your WordPress site. Whether you’re a novice user or a seasoned developer, WP Crontrol empowers you to take control of your site’s automation with ease.

  1. Advanced Cron Manager:

 This plugin provides a user-friendly interface to manage all WP-Cron tasks. It allows you to view, edit, delete, and schedule tasks effortlessly. Additionally, it provides insights into when each task last ran and when it’s scheduled to run next.

Steps to Set up and Manage WP-Cron schedule using Advanced CRON Manager:

Step 1: Install and Activate the plugin

Navigate to plugins and search for Advanced CRON  Manager.

Install the plugin and then activate it.

Cron Manager Install and Activate

Step 2: Access the Plugin

To access the plugin, navigate to Tools -> CRON Manager

Cron Manager access the plugin

Step 3: View the CRON Manager’s Dashboard

On accessing the CRON manager, you can view the list of all cron events and list of all cron schedules.

Step 4: Add a new CRON Event

With Advanced CRON Manager, you can easily add new CRON events by simply clicking on the Add new event button on Cron Manager’s dashboard.

Cron manager Add cron event

Provide the hook name with the php naming convention. E.g. smack_new_cron_event.

Then select the first execution date and recurring (Scheduled) time interval of the New Cron event.

Once done, Click on schedule event

Cron Manager schedule event

Step 5: Add new schedule

To add custom time schedule for wp- cron,

  • Navigate to the Add new schedule at the top of the Cron’s Manager dashboard page.
  • Provide the display name, slug and the select the schedule intervals as day, hour, minutes or seconds.
  • Once done click on Add schedule button. Now your new schedule will get added to the schedule list.
cron manager Add schedule event

The Advanced Cron Manager Plugin represents a significant advancement in task automation and scheduling, offering unparalleled flexibility, control, and efficiency for managing Cron jobs.

How does the CSV Importer help in WP-Cron management?

Now, let’s address the relationship between CSV importers and WP-Cron. CSV importers, commonly used for bulk data migration or updates, can benefit significantly from WP-Cron integration.

  1. Scheduled Imports: WP-Cron can be used to schedule CSV imports at specific intervals. While importing bulk records using a CSV importer, you have a scheduled import option that can benefit from WP-Cron. For example, if you regularly receive updated CSV files containing new data for your website, you can schedule WP-Cron to trigger the importer to update your database automatically.
  2. Batch Processing: Large CSV import can strain server resources and impact site performance. By integrating with WP-Cron, you can break down imports into smaller batches, spreading resource usage over time and ensuring a smoother experience for both site visitors and administrators.

In conclusion, WP Cron is a powerful tool for automating tasks within WordPress, and leveraging plugins can enhance its functionality and management capabilities significantly. Whether you’re scheduling content publication, performing maintenance tasks, or managing CSV imports, WP Cron plugins offer solutions to streamline your workflow and optimize website performance.

WP Ultimate CSV Importer Pro

WP Ultimate CSV Importer Pro

Get Ultimate CSV/XML Importer to import data on WordPress faster, quicker and safer.

How do I disable WP-Cron?

Disabling WP-Cron is not recommended unless you have a specific reason to do so. If your site experiences high traffic or if scheduled tasks are resource-intensive, you may consider disabling WP-Cron and setting up a server-level cron job instead to reduce server load and improve performance.

To disable WP-Cron in WordPress, you can add the following line to your wp-config.php file:

define(‘DISABLE_WP_CRON’, true);

This will prevent WP-Cron from running automatically. Instead, you can set up a server-level cron job to trigger wp-cron.php at regular intervals.

Understanding and properly configuring WP-CRON in WordPress is essential for ensuring the seamless execution of scheduled tasks and maintaining optimal site performance. Whether enabling WP-CRON through the wp-config.php file, verifying settings in the WordPress Dashboard, or hooking WP Cron in the task scheduler, each step contributes to a reliable and efficient cron system.

For troubleshooting, various methods are available, including checking the cron status, running pending cron events using WP-CLI, or simulating visitor access through cURL or Wget. By addressing WP-CRON-related issues promptly, you can prevent disruptions to tasks such as scheduled post-publishing, plugin updates, and garbage collection.

Remember that the frequency of running the cron system should align with your site’s needs, striking a balance between regular execution and minimizing the impact on server performance. With the right configurations and occasional manual interventions, you can boost the performance of your WordPress site, ensuring that it runs smoothly and efficiently, with an enhanced performance.

Hope you enjoyed reading this article. What do you think? Feel free to contact us at [email protected] or follow us on social media.