Check if function called by cron job
WordPress has a constant DOING_CRON that helps us know we’re doing the cron jobs or not. It’s defined in wp-cron.php file. So, you can check this constant in your code: if ( defined( ‘DOING_CRON’ ) ) { // Do something }