{"id":2276,"date":"2019-10-30T09:08:50","date_gmt":"2019-10-30T09:08:50","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2276"},"modified":"2025-05-28T20:47:24","modified_gmt":"2025-05-28T19:47:24","slug":"system-triggered-wp-cron","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/wordpress\/cron-scheduled-tasks\/system-triggered-wp-cron","title":{"rendered":"System triggered WP-Cron"},"content":{"rendered":"\n<p>You can disable the default triggering of wp-cron.php for any page load and instead have it triggered using the system cron.  This is based on the nifty guide here:<\/p>\n\n\n\n<p><a href=\"https:\/\/tommcfarlin.com\/wordpress-cron-jobs\/\">https:\/\/tommcfarlin.com\/wordpress-cron-jobs\/<\/a><\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Disable defult wordpress cron<\/h5>\n\n\n\n<p>Stop wp-cron.php being called for every page load (this is actually not a bad thing to do for heavily used sites).  In wp-config.php file add the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*Disable default wordpress cron call for every page load (we are setting the system cron to call it instead at specific times)*\/\ndefine('DISABLE_WP_CRON', true);<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Set your servers cron to trigger the wordpress cron<\/h5>\n\n\n\n<p>Use your servers management software or the command line to run the following cron task:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*\/15 * * * * wget -q -O - http:\/\/MYDOMAINNAME.com\/wp-cron.php?doing_wp_cron<\/code><\/pre>\n\n\n\n<p>You can use this code to display it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    $PathToCron = home_url('\/') . \"wp-cron.php?doing_wp_cron\";\n    $PathToCron = str_replace('https:\/\/', 'http:\/\/', $PathToCron);   \/\/Make sure it is http, not https, so that it works on localhost<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Create your function to be triggered<\/h5>\n\n\n\n<p>Create functions to register and de-register the cron with wordpress<\/p>\n\n\n\n<p>If creating a plugin you can register when the plugin is installed and de-register if it is deleted.  Otherwise create some way to carry out the register function call.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/***********************************\n\/\/***********************************\n\/\/********** CRON FUNCTION **********\n\/\/***********************************\n\/\/***********************************\nadd_action( 'my_cron_hourly_event',  'my_cron_hourly_event' );    \/\/&lt;&lt;&lt;Need to add namespace??\nfunction my_cron_hourly_event() {\n\n  \n  \/\/Do something\n\n}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Set it to be triggered by cron<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/******************************************************************************\n\/\/******************************************************************************\n\/\/********** REGISTER \/ DE-REGISTER OUR CRON FUNCTIONS WITH WORDPRESS **********\n\/\/******************************************************************************\n\/\/******************************************************************************\nfunction my_cron_events_activate() {\n    wp_schedule_event( time(), 'hourly', 'my_cron_hourly_event' );    \/\/&lt;&lt;&lt;Need to add namespace??\n}\n\nfunction my_cron_events_deactivate() {\n    wp_clear_scheduled_hook('my_cron_hourly_event');    \/\/&lt;&lt;&lt;Need to add namespace??\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can disable the default triggering of wp-cron.php for any page load and instead have it triggered using the system cron. This is based on the nifty guide here: https:\/\/tommcfarlin.com\/wordpress-cron-jobs\/ Disable defult wordpress cron Stop wp-cron.php being called for every page load (this is actually not a bad thing to do for heavily used sites). [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189],"tags":[],"class_list":["post-2276","post","type-post","status-publish","format-standard","hentry","category-cron-scheduled-tasks"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2276"}],"version-history":[{"count":11,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2276\/revisions"}],"predecessor-version":[{"id":5062,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2276\/revisions\/5062"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}