Hi folks… what I’m after is the ability to prevent featured images from loading at all on pages. I want my clients to be able to add a featured image to a page so that it shows up correctly on the OpenGraph when it’s shared on social, but I don’t want the image to display on the front end.
Yes, I know I can hide with CSS, but the image is still actually loading, which affects page speed. So I don’t want to just display:none
the featured image.
I’ve found this file generatepress > inc > structure > featured-images.php and I’ve added a conditional to line 59 to prevent the home page image from loading:
if ( ! has_post_thumbnail() || ! is_home() ) {
The above works and prevents the featured image from loading on the Home Page. Here are my issues…
(1) It doesn’t work with is_page()
for some reason to prevent loading on all pages, Only works for is_home()
.
(2) Also, I know hacking the theme isn’t the solution, but when I tried to move the file to my child theme (replicating the folder structure as I have with other themes and placing the php file inside), Generatepress is not picking up my revisions and is reading the core theme file instead.
I have the following folder structure in place: generatepress-child > inc > structure > featured-images.php.
If you could explain how to solve the above 2 issues or if you have a better way of accomplishing this (which is quite possibly something simple I’ve completely overlooked), I’d appreciate it!