How to Setup and Manage WordPress Cron Jobs

What is a WordPress Cron job?

WordPress cron jobs is an emulation of the UNIX cron system that automatically schedules tasks at custom intervals. It allows WordPress users to perform time-based tasks such as publishing scheduled posts and checking for updates while a page is loading.

图片[1]- 如何设置和管理 WordPress Cron 作业-光子波动网 | WordPress教程、Elementor教程与故障修复

What are the pros and cons of using WordPress Cron?

WP-Cron The system is veryEasy to set upThe WordPress cron job plugin is a great tool to help you get the most out of your WordPress cron job. Various WordPress cron jobs plugins have features that simplify the setup and management process.

By scheduling recurring tasks at customized intervals, you can save time and focus on other important tasks. In addition, the system ensures that you don't lose any data if a scheduled task doesn't run on time-something UNIX cron jobs can't do.

WP-Cron only runs when a user visits your site. Low-traffic WordPress sites will skip some jobs if no one triggers a page load, resulting in aPending cache accumulationand harms the loading time and performance of the site.

How to Manage WordPress Cron Jobs Using Plugins

The easiest way to set up and manage WordPress cron jobs is to use the cron job pluginUseWP CrontrolThe reason for this is that it is free and has all the necessary features.

1.Install WP Crontrol plugin

First, follow the steps below to install and activate the WordPress plugin for managing cron jobs:

  • Navigate from the WordPress admin dashboard toPlug-ins → Add new plugin.
  • Enter in the search fieldWP CrontrolPress enter to confirm, find the plug-in and clickInstallationThe
图片[2]- 如何设置和管理 WordPress Cron 作业-光子波动网 | WordPress教程、Elementor教程与故障修复
  • After the installation is complete, select"Activate."

Refresh the site after activation, and to see all the cron jobs running on the WordPress site, go from the dashboard to the"Tools" → "Cron Events".

图片[3]- 如何设置和管理 WordPress Cron 作业-光子波动网 | WordPress教程、Elementor教程与故障修复

Attention:Do not remove any of the default WordPress cron jobs (they have awp(Prefix). Otherwise it will break the core functionality of the site.

2. Add new Cron events

Now you can control WordPress cron jobs. To add a new cron event do the following:

  • interviewsCron Eventssubmenu and click theAdd New.
图片[4]- 如何设置和管理 WordPress Cron 作业-光子波动网 | WordPress教程、Elementor教程与故障修复
  • Set up a timed task (Cron event) and create a WordPress hook for it. Make sure the name of the hook conforms to PHP's naming convention. Choose when and how often the task will be executed. If you don't need additional parameters, you can leave the parameter boxes empty.
图片[5]- 如何设置和管理 WordPress Cron 作业-光子波动网 | WordPress教程、Elementor教程与故障修复
  • click (using a mouse or other pointing device)Add Event. If successful, a new cron event will appear in theCron event list.
图片[6]- 如何设置和管理 WordPress Cron 作业-光子波动网 | WordPress教程、Elementor教程与故障修复
  • Now that you have a hook, the next step is to add it along with the action that runs when the cron event is triggered.

3. Setting up Cron scheduling

The plugin provides four standard intervals to choose from, but it still allows users to create custom intervals. Please follow the steps below to add a new cron schedule:

  • Navigating from the WordPress Dashboard to"Settings" → "Cron Schedule".
  • Fill out the "Add Cron Program" form.fields under the section. Here we set the interval to 600 seconds (10 minutes). Use the PHP naming convention to create the interval name.
图片[7]- 如何设置和管理 WordPress Cron 作业-光子波动网 | WordPress教程、Elementor教程与故障修复
  • click (using a mouse or other pointing device)Adding a Cron Program. The new interval should appear in the list.

4. Editing Cron events

We have a custom interval, use it with a custom cron. Here's how to modify an existing cron event:

  • locate"Tools" → "Cron Events"and find the cron event we created earlier. Click on thecompilerThe
  • show (a ticket)"Repeat."drop-down menu and select10 minutes.The
图片[8]- 如何设置和管理 WordPress Cron 作业-光子波动网 | WordPress教程、Elementor教程与故障修复
  • click (using a mouse or other pointing device)Updated eventsThe

How to Setup WordPress Cron Jobs with WP-CLI

Another way to set up a WordPress cron job is to use theWP-CLI. This tool allows you to manage sites through a command line interface.

图片[9]- 如何设置和管理 WordPress Cron 作业-光子波动网 | WordPress教程、Elementor教程与故障修复

WP-CLI installation method: DownloadPhar file installation

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Next, check the Phar file to verify that it is working properly:

php wp-cli.phar --info

To use the WP-CLI by typing at the command line wpFor example, make the file executable and move it to a location in the PATH. For example:

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

If the WP-CLI installation was successful, you should see something similar to the following when you run itwp --info::

$ wp --info
OS: Linux 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64
Shell: /usr/bin/zsh
PHP binary: /usr/bin/php8.1
PHP version: 8.1.0
php.ini used: /etc/php/8.1/cli/php.ini
MySQL binary: /usr/bin/mysql
MySQL version: mysql Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
SQL modes.
WP-CLI root dir: /home/wp-cli/
WP-CLI vendor dir: /home/wp-cli/vendor
WP_CLI phar path: /home/wp-cli/
WP-CLI packages dir: /home/wp-cli/.wp-cli/packages/
WP-CLI global config: /home/wp-cli/.wp-cli/packages/
WP-CLI project config: /home/wp-cli/wp-cli.yml
WP-CLI version: 2.10.0

To access existing cron events, enter the following command in the terminal:

wp cron event list

The following commands will show additional commands that can be used with the WP-CLI:

wp help

WordPress cron jobs make it easy to schedule tasks at customized intervals. Although WP-Cron has some drawbacks, using this utility can help you perform administrative tasks more efficiently.


Contact Us
Can't read the tutorial? Contact us for a free answer! Free help for personal, small business sites!
客服微信
Customer Service
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: [email protected]
Working hours: Monday to Friday, 9:30-18:30, holidays off
© Reprint statement
本文作者:红牛独立站
THE END
If you like it, support it.
kudos0 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments