If you run a WordPress website, you may need to automate regular tasks, such as scheduling posts, sending emails to subscribers, or updating plugins. WordPress uses an internal scheduling service called a cronjob to automate these tasks. By default, WordPress does this through WP-Cron which simulates a cron job. However, using WP-Cron on a high-traffic website can cause performance issues and affect your page load times.
In this article, you will learn how to run the WordPress cronjob via crontab or a management software like Plesk to improve the efficiency of your website and ensure that all scheduled tasks are executed automatically.
Table of contents
Step 1: Understanding the WordPress cronjob
Before you begin, you need to understand what the WordPress cronjob is and how it works. The WordPress cronjob is an internal scheduling service that automatically runs WordPress tasks at regular intervals. However, this service only runs when a page is accessed on your website. This means that if there is little traffic on your site, some of the scheduled tasks may not run. To ensure that all tasks are executed, you can run the WordPress cronjob through crontab or a management software like Plesk:
Step 2: Access your server
To run the WordPress cronjob via Crontab or Plesk, you must have access to your server. With many web hosts, you can usually access a Plesk or cPanel dashboard to set up the cronjob.
If you do not have access to a dashboard, you may need to access your server via SSH (Secure Shell). If you are not familiar with working on the command line and have no experience with SSH, you should consult an experienced administrator.
Step 3: How to disable WP-Cron
To disable WP-Cron and use a proper system cron instead, you can simply add the following code to your wp-config.php file:
define( 'DISABLE_WP_CRON', true );
This line should be inserted right before the line that says "That's all, stop editing! Happy blogging.". Note, however, that this will prevent WP-Cron from running when the page loads. If you call it directly from wp-cron.php, it will still run.
Step 4: Create a cronjob schedule file
After accessing your server, you need to create a cronjob schedule file. This file contains the instructions that the server will execute to run the WordPress cronjob.
You can either create the file manually or use a management software like Plesk to create it automatically. If you create the file manually, you can use a text editor such as nano or vim. It is important that you specify the instructions for the cronjob correctly to ensure that it runs properly.
Step 5: Set up the cronjob
Once you have created the file, you need to set up the cronjob to run the file. If you are using a management software like Plesk, you can set up the cronjob directly from the Dashboard. Otherwise, you can set up the cronjob through the terminal or SSH.
The syntax for setting up the cronjob is as follows:
* * * * path/to/PHP/Binary -f path/to/wp-cron.php > /dev/null
The asterisks (*) represent the time parameters that specify the time when the cronjob is executed. The first asterisk indicates the minute, the second indicates the hour, the third indicates the day of the month, the fourth indicates the month, and the fifth indicates the day of the week.
You must specify the path to the PHP binary and the wp-cron.php file. Make sure that you specify the path to your WordPress installation and that the path to the PHP binary is correct.
Step 6: Saving the cronjob schedule file
After you set up the cronjob, you need to save the cronjob schedule file. If you created the file manually, simply save it to the correct directory on your server.
If you are using a management software like Plesk, the file will be saved automatically once you have set up the cronjob.
Step 7: Testing the cronjob
Once you have set up the cronjob and saved the schedule file, you can test it. To do this, simply run the cronjob manually and verify that all scheduled tasks are executed. This is important to make sure that your website is working properly and all the required tasks are being executed.
If the cronjob runs successfully, you can be sure that it will be executed automatically on a regular basis. You no longer have to worry about whether your scheduled tasks will be executed or not.
Setting up the WordPress cronjob via crontab or management software like Plesk can be a bit complicated, but it's a necessary task to ensure that all scheduled tasks are performed automatically. By setting up the cronjob correctly, you can improve your site's performance and ensure that important functions like updating plugins, sending emails, and scheduling posts run smoothly.
If you are unsure how to set up the cronjob or simply don't have the time, we are here to help. Our experienced team of WordPress experts can take care of setting up and optimizing your WordPress cronjob for you, so you can focus on other important aspects of your online business. Do not hesitate to contact us at contact, to learn more about our services and find out how we can help you improve the performance of your WordPress website.