Check if WordPress frontend is attempting to be displayed

/*
 * is_frontend()
 *
 * @return boolean
 */
function is_frontend() {
   return ( ! is_admin() || wp_doing_ajax() );
}

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).

Leave a Comment