The IR messages are actually pulses that are modulated around 36 KHz. Some libraries, like the commonly used IRremoteESP8266, do all the timing in-line. So the modulation is achieved by bit banging the GPIO line driving the IR LEDS with software delays in between. This works well when not much else is going on but can be disturbed if any other software interrupts and disturbs this timing.
You have 2 main choices here I think.
First, you can try and find which bit of code is disturbing the IR and then work around it by say disabling it during the period when you want to transmit an IR signal. You should be able to find the culprit by adding in the extra pieces of code one at a time.
The second choice is to use IR transmission code which is less dependent on in-line timing. I do this in my ESP IR Blaster https://www.instructables.com/id/ESP-12 ... d-Blaster/ This exploits the ESP8266 ability to do the modulation in hardware and then uses interrupts to do the much slower bit bang timing.