How to detect if it is an AJAX request in WordPress?

Update: since WordPress 4.7.0 you can call a function wp_doing_ajax(). This is preferable because plugins that “do Ajax” differently can filter to turn a “false” into a “true”.


Original answer:

If you’re using Ajax as recommended in the codex, then you can test for the DOING_AJAX constant:

if (defined('DOING_AJAX') && DOING_AJAX) { /* it's an Ajax call */ }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)