Preload image: LCP doesnt work

I’m having problems with the LCP, in webpagetest it tells me that I have to put this to prioritise the image “This experiment adds a to the head of your HTML document, causing browsers to request the image earlier and at a higher priority than it otherwise might.” Which I did in php with variables with the following code sometimes it loads fine, but sometimes it loads poorly and I get the same recommendation. Any idea what I could do, bearing in mind that I can’t stop using the variables.