is_admin() is a quirky function, and its accidental mis-use can cause issues with AJAX-based plugins.

The problem

Many developers assume that is_admin() will return TRUE only when a user is logged into the admin area, but that isn’t the case. According to the documentation page:

In other words, is_admin does not check whether the user is logged in.

AJAX requests

When a plugin makes a WordPress AJAX request, it uses /wp-admin/admin-ajax.php. This is technically an admin page, so is_admin() returns TRUE, even for front-end requests.

The solution

Use the wp_doing_ajax() function to check whether AJAX is being used.


if ( is_admin() ) {


if ( is_admin() && ! wp_doing_ajax() ) {