How to replace WordPress cron with a real cronjob

Configuring a Cron Job for a WordPress website is crucial to ensure that scheduled tasks execute on time and without issues. This helps prevent failures in scheduled jobs or events, ensuring everything operates smoothly. This includes tasks like processing emails, sending messages, executing automation, managing email sequences, and handling other processing activities.

WordPress relies on various scheduled background tasks to ensure your website operates efficiently. Whenever a user visits a page, the wp-cron.php file is triggered. This file checks for any scheduled tasks that need to run and executes them if they are due.

While this method is effective, it can be vulnerable to distributed denial of service (DDoS) attacks. Frequent, high-volume requests to the wp-cron.php file, also known as cron jobs, can lead to increased server load, which might cause your website to timeout and prevent scheduled tasks from executing properly.

If you’re concerned about this issue, you can modify how WordPress handles scheduled tasks by replacing the default wp-cron.php call with a standard cron job managed by your server’s operating system.

To begin, you need to disable the WordPress cron job. You can do this by using an FTP client and a text editor or through the cPanel File Manager to edit the wp-config.php file located in the main directory of your WordPress installation.

Add the following line:

define( 'DISABLE_WP_CRON', true );

After that, you should create a real cron job to run the wp-cron.php file. You can configure it to trigger every minute, every 5 minutes, or even every 30 minutes if you’re managing a simple website. Depending on your hosting, usually you can access the server cron jobs feature in your cPanel/hosting server dashboard.

If wp-cli is installed on your server, you can run this command:

cd /home/www/yourdomain.com/public_html; wp cron event run --due-now >/dev/null 2>&1

Replace “/home/www/yourdomain.com/public_html”  with the actual path to your WordPress application’s core files. If wp-cli is not installed, you can simply use wget or even curl command to call the WP cron file.

wget -q -O - https://uptonines.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1

OR with CURL

curl "https://uptonines.com/wp-cron.php?doing_wp_cron" > /dev/null 2>&1

Replace “https://uptonines.com/” with your website URL.

That’s it. Now your website running a real cron job. Enjoy!