Archived topic
Featured Image -> Use on other template?
1 reply · Started by Nikolas on May 17, 2021
Hello,
I am using Generatepress and in the customizer I have specified the featured image to be placed outside the container. I am using a plugin for CPT's and was wondering if I can copy the same style for the Featured Images as GP uses. What would be the php line that I should copy?
Hi there,
Can you specify where you want the featured image to be placed?
We can move the featured image outside of its default container by filtering its output(on archive pages), making a child theme template (for single post pages), Moving it out by making a template using the Block Element or removing it entirely and re-adding it using Hooks.
But there may be a problem with the styling because if you move the featured image outside of the container, you're going to affect the styling because of a potential CSS selector mismatch.
For filtering the output(archive pages), you can use generate_featured_image_output filter.
For moving it by making a child theme, this can be tedious because you basically have to copy this file and edit it to the way you prefer - https://github.com/tomusborne/generatepress/blob/master/inc/structure/featured-images.php
For making a template for it using Block Element, I think it's best to watch a video first on how the new GP premium 2.0's Block element work. It allows you to rearrange how the site looks using WordPress' Gutenberg editor.
For removing it entirely and re-adding it back in using hooks, you can disable the featured image by unchecking "Display featured image" on the customizer settings. After disabling, you add it back manually outside of the container using a Hook element containing a PHP code to re-render the post's featured image.
The 2nd and the 4th option will require PHP, if you decide on these 2, let me know so I can help with the coding writeup.