May 9, 2021 at 8:30 pm #281614
Hello, I want to preload a slider image but only on the front page. I have inserted some code into the header.php file and placed it in the child theme, and it is preloading the image. This works well. However, it preloads the image on every page. I only want it to preload on the front page. Can you assist me to wrap the link tag with a php if condition? The website is iglobal.net and the link tag I am using is: <link rel=’preload’ href=’/wp-content/uploads/2020/07/Playa-Hermosa-014-Home-Page.jpg’ as=’image’> Thank you!May 10, 2021 at 2:08 am #281657May 10, 2021 at 6:49 am #281667
Yes indeed, a child’s theme is a great idea, that is why I created one about 4 years ago. So that is already taken care of. Can you assist with the code?
EdwinMay 10, 2021 at 6:51 am #281668
@mmhgloba: Hello Edwin,
I have attached a link in the reply above where the code is. Can you try using that?
Let me know if this works out!
SkandhaMay 10, 2021 at 7:05 am #281669
Thanks for the follow up. I noticed that and tried it. It is not working,. Please see the google lighthouse audit and also the screenshot of how I have code entered in the child’s theme.
Please have a another look at it to resolve the issue.
EdwinMay 11, 2021 at 1:44 am #281734
This is resolved 🙂May 11, 2021 at 3:28 am #281671
When I insert the code directly into line 41 in the child’s theme in this format – <link rel=’preload’ href=’/wp-content/uploads/2020/07/Playa-Hermosa-014-Home-Page.jpg’ as=’image’> – it works and the google error goes away and the performance score increases by 15 points. When I replace the above code with your code, it invalidates the preload. So the new code is blocking the preload command.
But with the code inserted as described, it preloads the image on every page not only the home page.May 11, 2021 at 3:28 am #281737
- The topic ‘Preload Image’ is closed to new replies.