Configure WordPress cron job for your websiteMay 14, 2019·4 min read
A cron job is a task scheduled to run automatically at specific intervals. For example, a cron job could automatically back up a file every six hours.
In its default configuration, WordPress does not use a real cron job for scheduling and other related tasks. Instead, whenever a page is loaded on a WordPress site, WordPress runs the wp-cron.php file. Although this “virtual” cron job is convenient, it has a few drawbacks:
- Running the
wp-cron.phpfile every time WordPress loads a page is unnecessary, and can negatively affect server performance, particularly on sites that receive a lot of traffic.
- For a site that does not receive a lot of traffic on the other hand, it can be a significant amount of time before a visitor loads a page (and triggers the cron task). This can cause missed schedules for publishing posts and other unintended effects.
To resolve these issues, you can disable the default virtual WordPress cron job, and configure a real cron job. To do this, follow the procedures below.
To disable the default virtual WordPress cron job, follow these steps:
- Log in to your account using
- Using the cPanel
File Manageror the
command line, open the
wp-config.phpfile in a text editor.The
wp-config.phpfile is located in the directory where you installed WordPress. Usually, this is the public_html directory.
- Add the following line to the wp-config.php file:
- Save the changes to the
wp-config.phpfile and then exit the text editor. The virtual WordPress cron job is now disabled.
After you have disabled the default WordPress cron configuration in the
wp-config.php file, you are ready to set up a real cron job that runs at fixed intervals regardless of site traffic.
If your account includes cPanel access, you can use it to configure the cron job. Otherwise, you can configure the cron job from the command line.
To set up a WordPress cron job using cPanel, follow these steps:
- Log in to cPanel.
- In the
Advanced sectionof the cPanel home screen, click
- Under Cron Email, type the e-mail address that you want to receive notifications, and then click Update Email. Every time the cron job runs, the e-mail account will receive a message.If you do not want to receive e-mail notifications for the cron job, you can append
>/dev/null 2>&1to the command, which redirects all output to
- Under Add New
Cron Job, in the Common Settings list box, select Twice an hour.You can run cron jobs a maximum of every
15 minuteson shared and reseller accounts. A 30-minute interval for the WordPress cron job should be more than sufficient.
- In the Command text box, type the following line. Replace username with your own A2 Hosting account
/usr/local/bin/php -q wp-cron.phpThis line assumes that you installed WordPress in the document root (public_html) directory. If you installed WordPress in another directory, modify the cd command to change to that directory instead.
- Click Add New Cron Job. The new cron job settings take effect immediately.
To set up a WordPress cron job using the command line, follow these steps:
- Log in to your account using
- At the command prompt, type the following command:
oto enter editing mode and start a new line of text.
- Type the following line, replacing username with your own A2 Hosting account username:
*/30 * * * * cd /home/username/public_html; /usr/local/bin/php -q wp-cron.php
- This line sets the cron job to run every 30 minutes. If you are on an unmanaged platform (such as a Dynamic VPS) you can run cron jobs as frequently as you want. On shared and reseller accounts, however, you can only run cron jobs a maximum of every 15 minutes. A 30-minute interval for the WordPress cron job should be more than sufficient.
- This line assumes that you installed WordPress in the document root (public_html) directory. If you installed WordPress in another directory, modify the cd command to change to that directory instead.
:wqand then press
Enter. The new cron job settings take effect immediately.
Go back Home.