Control a device using physical button online and offline

Hey i am using node mcu 1.0 with relay for my project. i need to attach a physical button to control the lights. If there is no internet connection then device work with physical button and if there is internet available it work with blynk app as well as physical button. As with my current codes it got stuck with wifi manager. Please help me for the wifi manager and checking the wifi connection by specific interval of time.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>  // Essential for all Blynk Projects

char auth[] = "xxxxxxxxxxxxxxxx";

bool Connected2Blynk = false;
#define RELAY D4
#define TOUCH D7
bool relay = HIGH;


SimpleTimer timer;

void setup() {
 Serial.begin(115200);
 delay(10);
 pinMode(RELAY, OUTPUT);
 pinMode(TOUCH, INPUT);

 // check if still connected every 11 seconds
 Serial.println("\nStarted");
 MyWiFi();
}
void MyWiFi() {
 int mytimeout = millis() / 1000;
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
   if ((millis() / 1000) > mytimeout + 3) { // try for less than 4 seconds to connect to WiFi router
     break;
   }
 }

 if (WiFi.status() == WL_CONNECTED) {
   Serial.print("\nIP address: ");
   Serial.println(WiFi.localIP());
 }
 else {
   Serial.println("\nCheck Router ");
 }
 Blynk.config(auth);
 Connected2Blynk = Blynk.connect(1000);  // 1000 is a timeout of 3333 milliseconds
 mytimeout = millis() / 1000;
 while (Blynk.connect(1000) == false) {
   if ((millis() / 1000) > mytimeout + 3) { // try for less than 4 seconds
     break;
   }
 }
}

void connectwifi() {
 WiFiManager wifiManager;
 wifiManager.autoConnect("Home Automation");
 Serial.println("Wifi is connected");
}

void CheckConnection() {
 Connected2Blynk = Blynk.connected();
 if (!Connected2Blynk) {
   Serial.println("Not connected to Blynk server");
   MyWiFi();
 }
 else {
   Serial.println("Still connected to Blynk server");
 }
}
BLYNK_WRITE(V0)
{
 relay = param.asInt();
 digitalWrite(RELAY, relay);
 Serial.println("Button pressed");
}

void loop() {
 if (digitalRead(TOUCH))
 {
   relay = !relay;
   digitalWrite(RELAY, relay);
   Blynk.virtualWrite(V0, relay);
   delay(600);
 }

 if (WiFi.status() != WL_CONNECTED) {
   connectwifi();
 }

 if (Connected2Blynk) {
   Blynk.run();  // only process Blyk.run() function if we are connected to Blynk server
 }
 timer.run();
}