Tagged: theme
- This topic has 7 replies, 2 voices, and was last updated 3 years, 4 months ago by Skandha.
-
AuthorPosts
-
May 9, 2021 at 8:30 pm #281614EdwinParticipant
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 #281657SkandhaParticipantMay 10, 2021 at 6:49 am #281667EdwinParticipantHi Skandha,
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?
Thank you,
EdwinMay 10, 2021 at 6:51 am #281668SkandhaParticipant@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!
Kind Regards,
SkandhaMay 10, 2021 at 7:05 am #281669EdwinParticipantHi Skandha,
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.
https://iglobal.net/wp-content/uploads/2021/05/Lighthouse-score.jpg
https://iglobal.net/wp-content/uploads/2021/05/php-insert.jpgPlease have a another look at it to resolve the issue.
Thanks,
EdwinMay 11, 2021 at 1:44 am #281734EdwinParticipantThis is resolved 🙂
May 11, 2021 at 3:28 am #281671EdwinParticipantWhen 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 -
AuthorPosts
- The topic ‘Preload Image’ is closed to new replies.