Disabling wp-cron.php execution in wordpress

Follow

WordPress uses a file called wp-cron.php as a scheduled task in order to automate things like publishing scheduled posts, checking for plugin or theme updates, sending email notifications and more.

By default WordPress is setup to call wp-cron.php everytime someone visits your WordPress website.

In higher volume websites, this can cause excessive 

Disable default wp-cron.php behavior

  • Open wp-config.php using File Manager, or FTP.
  • Add the highlighted line to the wp-config.php, after the DB_COLLATE line mentioned. An example is how it should look below.
/** The Database Collate type. Don't change this if in doubt. */ 
define('DB_COLLATE', '');

define('DISABLE_WP_CRON', 'true');

Setup manual cron job for wp-cron.php

You still need to leave wordpress with the ability to automatically run tasks, and updates, so now we need to setup a cronjob 

You can add a cronjob as per the below articles for cPanel and Plesk

How do I create a cronjob in cPanel ?

How do I create a cronjob in Plesk ?

 

For cPanel
The example line you would need to add is

cd /home/username/public_html; php -q wp-cron.php >/dev/null 2>&1

Where in the above example, is the path to your wordpress install, Normally in your public_html directory on a normal install.

The highlighted username, generally is your cPanel username, for an example path.

You can then organise it for once per day, say at 3AM, so it's off-peak of actual website usage.

For Plesk
The example line you would need to add is

cd /var/www/vhosts/domainname.com/httpdocs; php -q wp-cron.php >/dev/null 2>&1

Where in the above example, is the path to your wordpress install, Normally in your httpdocs directory on a normal install.

The highlighted domain name, generally is your website, for an example path.

You can then organise it for once per day, say at 3AM, so it's off-peak of actual website usage.

Note:

For plesk, you also have the option of running a PHP Script. This may work better, as you can just browse to the file you need to execute, in this case wp-cron.php, and it will setup the commands automatically.

Have more questions? Submit a request

Comments

Powered by Zendesk