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. In the “Command” text box, enter the following line-
    */30 * * * * cd "${HOME}/public_html" && /usr/local/bin/php -q wp-cron.php >/dev/null 2>&1

    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.

  5. Save and exit. In Vim, press Esc, type :wq, then press Enter. In nano, press Ctrl+O, Enter, then Ctrl+X. The change takes effect as soon as you save. 
  6. (verify): 
    crontab –l
  7.  (disable the built-in WordPress cron, in wp-config.php above “That’s all, stop editing!”): 
    define( ‘DISABLE_WP_CRON’, true ); 

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