Home › Forums › Support › Disable Featured Image Not Working In Content Template (even with snippet)
- This topic has 18 replies, 3 voices, and was last updated 3 years, 2 months ago by
Ying.
-
AuthorPosts
-
February 12, 2023 at 8:58 pm #2530938
John
Hi team,
I use GP Premium and GB Pro.
I have created a content template for my Pages. When I use it, the Featured Image always shows up, even if I try to disable it with GP disable elements feature.
I used this snippet from David on another thread:
add_filter( 'render_block', function( $block_content, $block ) { if ( !is_admin() && is_single() && ! empty( $block['attrs']['className'] ) && 'respect-disable-featured-image' === $block['attrs']['className'] && has_post_thumbnail() && get_post_meta( get_the_ID(), '_generate-disable-post-image', true ) === 'true' ) { $block_content = null; } return $block_content; }, 10, 2 );Unfortunately it still doesn’t work, I don’t why. Can you help? Thank you
February 12, 2023 at 10:24 pm #2530967Fernando Customer Support
Hi John,
For that Page, you’re using a Block Element – Content Template which has a Block loading the Featured Image. See: https://share.getcloudapp.com/GGuJY9db
You can either delete that or modify it to whatever you prefer.
February 12, 2023 at 10:27 pm #2530968John
Hi Fernando,
Yes, and I’m hoping to disable it using the script in the post. My source is https://generatepress.com/forums/topic/disable-elements-featured-image-not-working-in-content-template/#post-2530939
February 12, 2023 at 11:04 pm #2530987Fernando Customer Support
Are you planning to disable it for specific pages only?
February 13, 2023 at 1:26 am #2531085John
Yes, exactly
February 13, 2023 at 1:58 am #2531123Fernando Customer Support
I believe the easy approach to this would be just to create 2 instances of the Content Template.
The approach you want initially would only work if you already have a custom Post Meta field called:
_generate-disable-post-image.If you do, you can just
respect-disable-featured-imageto the class list of your Image Block. With that, the PHP should work.Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
February 15, 2023 at 7:00 pm #2534884John
Fernando, I’m confused by your response compared to David’s in the other thread I linked to. There doesn’t seem to be any custom field manually created to make that script work, did I misunderstand?
My assumption was that
_generate-disable-post-imagewas a field generated by GP itself when the Disable Featured Image is checked.Creating 2 content templates is not an easy approach for me at all… I can’t count on my website editors to go manage the Elements display options, however it’s much easier for them to check “Disable Featured Image” in the post itself
February 15, 2023 at 7:27 pm #2534896Fernando Customer Support
Oh yes. Thank you for reminding me of that.
That code should indeed work. Just add
respect-disable-featured-imageto the class list of your Image Block.Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
February 15, 2023 at 9:42 pm #2534962John
Yes, I understand it should work 🙂 but it doesn’t. Hence this post, I’m trying to resolve why it doesn’t work
February 15, 2023 at 9:54 pm #2534968Fernando Customer Support
Can you try creating a Layout Element and disabling the Featured image from there? Reference: https://docs.generatepress.com/article/layout-element-overview/#disable-element
February 16, 2023 at 10:57 am #2535918John
I did and it doesn’t disable the Featured Image from the Content Template
February 16, 2023 at 11:47 am #2535979Ying
StaffCustomer SupportCan you try changing the class to
page-header-imagefor in the content template?February 16, 2023 at 12:05 pm #2535993John
Ying, thank you it seems to work! The result is:
– If I disable the Featured Image from the Hero element, it removes the default featured image from the default template, but NOT the featured image from the Content Template.
– If I disable the Featured Image from the page itself, it ALSO removes the featured image from the Content Template.In the end, it gives me the intended result!
However I’m trying to understand: I disabled the PHP script that David had suggested in the other thread, and your solution still works. So no snippet is needed for this to work? Is
page-header-imagea default class from the theme?February 16, 2023 at 12:10 pm #2535999Ying
StaffCustomer SupportThe Disable featured image option in the post/page editor is using CSS, not PHP.
I read the topic and understand that it’s easier for authors to tick that box in the post/page editor.
So as long as the container or image has the
page-header-image, it will be hidden by GP’s theme CSS.In this case, no PHP snippet is required. But please be noted, this solution is hiding the image, not removing the image.
February 16, 2023 at 12:14 pm #2536000John
Oooh I see. I didn’t realize that. That’s less than ideal because that image is one of the heaviest file to download on most pages… It’s a shame to force users to download it.
Is there any way to make David’s script work?
-
AuthorPosts
- You must be logged in to reply to this topic.