Archived topic
Remove featured image from html
4 replies · Started by Ryan on April 15, 2021
I know featured images can be hidden from pages but it just does it with css. The featured image is still included in the html. Due to some hero image optimization in the latest version of amp, it doesn't work correctly if a featured image is included in the html but hidden with css. Would there be a way to actually fully remove the featured image from the html on certain pages, however still have the featured image selected on a page for other reasons like sharing. Thanks!
Hi there,
The featured image not rendered on HTML if you uncheck it on Appearance > Customize > Layout > Blog for Archive.
But if you want to remove the featured image on specific posts or pages, you can use the Layout Element and specify the posts and pages on the display rule location. https://docs.generatepress.com/article/layout-element-overview/#disable-element
Maybe I misunderstood, but selecting to disable the featured image just disables it with display:none in css not by actually removing the html. I want the featured image in my blog and archives, it's only on pages that I want it disabled. I think if you have a function I could add to remove the featured image html on on pages but not posts and archives that would work for me. Thanks.
I think I figured it out, if you disable it in the customizer for all pages instead of doing it in the individual page settings then it seems to remove the html. Thanks!
Maybe I misunderstood, but selecting to disable the featured image just disables it with display:none in css not by actually removing the html.
No, it actually removes the element from the DOM structure. The whole <div class="featured-image page-header-image-single ">...</div> is removed from the page.
I think I figured it out, if you disable it in the customizer for all pages instead of doing it in the individual page settings then it seems to remove the html. Thanks!
Glad you got it sorted. :)