Check if WordPress frontend is attempting to be displayed

Checking for is_admin is not enough to verify if frontend is being displayed, as is_admin returns true when trying to make an ajax request even on frontend (http://codex.wordpress.org/Function_Reference/is_admin).

/*
 * is_frontend()
 * returns boolean
 */
function is_frontend() {
   return ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) ? true : false;
}

No comments yet.

Leave a Reply