How to use SD and WiFi at the same time ?

If that works ok, then copy and paste your wifi startup where I put the comment. Then it should start the wifi ok. The SD library begin() function call returns with the SD SPI disabled (D4 HIGH).

edit. Once these SS lines are initialized, you do not need to manipulate them anywhere else. The libraries will take care of that in the low level read/write functions.