How to Schedule Tasks with WordPress Cron Jobs (Command Line)

June 6, 2024 / WordPress

In this article, we will explain how to set up a WordPress cron job using the command line.

Let us follow the simple steps:

  1. Log into your account using SSH.
  2. Enter the following command-
    crontab –e
  3. Enter “O” to go to the edit mode and start a new line of text.
  4. Now, enter the below-outlined by replacing “username” with your account username.
  5. In the “Command” text box, enter the following line-
    */30 * * * * cd ${HOME}/public_html; /usr/local/bin/php -q wp-cron.php

    Important note- This line sets the cron job to run every 30 minutes. On unmanaged platforms, you can schedule cron jobs as often as needed. However, on shared and reseller accounts, the maximum frequency is every 15 minutes. A 30-minute interval for the WordPress cron job is generally sufficient.Keep in mind that this example assumes WordPress is installed in the document root (public_html) directory. If your WordPress installation is in a different directory, update the ‘cd’ command to reflect the correct path.

  6. Press the “Esc” key, type “:wp”, and then press, “Enter” to save the changes. The updated cron job settings will take effect immediately.

By setting up a WordPress cron job using the command line, you can improve your website’s performance and automate various tasks efficiently.

Hope you liked our article!

Spread the love