- This topic has 7 replies, 2 voices, and was last updated 2 years, 9 months ago by
Tom.
-
AuthorPosts
-
August 8, 2019 at 4:12 pm #979420
Steven
I see the option for a fallback image if there isn’t a feature image associated on a page that has a hero Element applied. However, I’m wondering if there’s a way to have the space the hero takes up suppressed if no feature image is selected for a particular page. If not, it would be great to have that as an option on the Appearance > Elements > Page Hero settings page or have this be the default behavior. I know you can use the Element display rules, but that will get out of hand with 2,000+ pages on our site.
August 8, 2019 at 5:09 pm #979449Tom
Lead DeveloperLead DeveloperHi there,
What do you mean by suppressed exactly? Like remove the entire Element if no featured image exists?
Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 9, 2019 at 8:42 am #980030Steven
Yes – if there’s no feature image, the whole element would be removed.
August 9, 2019 at 9:00 am #980046Tom
Lead DeveloperLead DeveloperTry this:
add_filter( 'generate_header_element_display', function( $display, $element_id ) { if ( 123 === $element_id ) { // Only target specific Element if ( ! has_post_thumbnail() ) { $display = false; } } return $display; }, 10, 2 );
Just update
123
to the ID of your Element.Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 9, 2019 at 10:40 am #980162Steven
I’m still new to WordPress so might not be adding this filter correctly. I created a child theme and placed the following in the child theme functions.php file:
<?php add_filter( 'generate_header_element_display', function( $display, $element_id ) { if ( 11089 === $element_id ) { // Only target specific Element if ( ! has_post_thumbnail() ) { $display = false; } } return $display; } );
When I do this, all of the site pages are blank. When I remove all content from the child theme functions.php file, the site renders as expected while the child theme is still active. So I think the child theme is set up correctly.
Am I missing a step?
August 9, 2019 at 7:49 pm #980393Tom
Lead DeveloperLead DeveloperAh, sorry! Can you try the updated code here?: https://generatepress.com/forums/topic/suppressing-hero-on-pages-without-feature-image/#post-980046
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 12, 2019 at 10:48 am #982297Steven
Thanks you! That appears to have done the trick π
August 12, 2019 at 4:46 pm #982482Tom
Lead DeveloperLead DeveloperAwesome, glad I could help π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.