Many times I have code and I want to make sure it only runs in a cron context, or it never runs in a cron context.

Is there an is_cron_running style function?

  • 1
    I'm a bit fed up of constantly googling for the answer to this then forgetting it, and the SEO on stack exchange is pretty good – Tom J Nowell Dec 1 '18 at 20:10

Yes, wp_doing_cron will return true if the current request is a WP Cron request, or if it's triggered from WP CLI


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.