There are instances where you want to check if the ESP8266 is connected to a Wifi AP and if the AP does have internet connectivity or not. In those situations try the code below

#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>

const char* ssid     = "ssid";
const char* password = "password";

void setup() {
  Serial.begin(115200);
  delay(10);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  } 
/* If you are here you successfully connected to your access point */

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  delay(5000);
  Serial.print("Pinging ip ");
  Serial.println("www.google.com");

  if(Ping.ping("www.google.com")) {
    Serial.println("Success!!"); /* if the code reaches here you are good to go */
  } else {
    Serial.println("Error :(");
  }
}