How to check if I am in admin-ajax.php in WordPress?

Posted by Editorial Staff | Updated on

Check the constant DOING_AJAX. Its definition is the first working code in wp-admin/admin-ajax.php. Some very weird plugins, like Jetpack, are defining that constant in unexpected places, so you might include a check for is_admin() as well.

I have asked for a simpler way to check this a long time ago, and this was finally implemented in 4.7.0.

So for WP 4.7 and higher you can use:

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers