- This topic has 7 replies, 3 voices, and was last updated 3 years, 8 months ago by David.
-
AuthorPosts
-
July 2, 2020 at 8:45 pm #1350092Steven
We have a filter working so the hero is suppressed when the Disable Element > Feature Image / Page Header is selected.
//Hide hero when feature image/header disabled for a page add_filter( 'generate_header_element_display', function( $display, $element_id ) { if ( 11089 === $element_id ) { // Only target specific Element if ( has_post_thumbnail() && get_post_meta( get_the_ID(), '_generate-disable-post-image', true ) === 'true' ) { $display = false; } } return $display; }, 10, 2 );
Can this filter be modified to suppress a breadcrumb container as well if the feature image/page header element is disabled?
Trying to figure out an easy way to suppress breadcrumbs on pages where we’ve suppressed the hero and title so we can add a slider and h1 for the title. I know we can manually add specific pages to the exceptions list for the element that’s injecting the breadcrumb, but we’re hoping for something admins don’t need to maintain and page editors can just apply themselves.
Thanks for any tips you can send our way.
July 3, 2020 at 5:05 am #1350416DavidStaffCustomer SupportHi there,
if the Breadcrumb is added using a Hook you would use the
generate_hook_element_display
filterhttps://docs.generatepress.com/article/generate_hook_element_display/
And your function would use the same conditional logic as your current header element function.
July 7, 2020 at 12:23 pm #1355671StevenHmmm…I’ve tried the following and it doesn’t seem to suppress the breadcrumb when the disable title element option is selected for a page:
//Hide breadcrumb on pages with title disabled add_filter( 'generate_hook_element_display', function( $display, $element_id ) { if ( 12085 === $element_id) { // Only target maing breadcrumb element if ( has_post_thumbnail() && get_post_meta( get_the_ID(), '_generate-disable-headline', true ) === 'true' ) { $display = false; } } return $display; }, 9, 2 );
July 7, 2020 at 2:58 pm #1355807TomLead DeveloperLead DeveloperHmm, looks like it should work.
Instead of checking for the disable content title post meta, try using this function:
generate_show_title()
.So:
if ( has_post_thumbnail() && ! generate_show_title() ) { }
July 7, 2020 at 3:41 pm #1355829StevenTried the code below and it doesn’t appear to be suppressing element with ID 12085 when the Page > Disable Elements > Content Title is selected for the following page:
https://bhamdev.wpengine.com/visiting
//Hide breadcrumb on pages with feature image / title disabled add_filter( 'generate_hook_element_display', function( $display, $element_id ) { if ( 12085 === $element_id) { // Only target specific Element if ( has_post_thumbnail() && ! generate_show_title()) { $display = false; } } return $display; }, 10, 2 );
July 8, 2020 at 3:37 am #1356244DavidStaffCustomer SupportI tested that condtion and it works for me – which means either the ID is incorrect or there is something conflicting.
Instead of disabling the element you could include the condtion inside the Hook Element itself eg.
<?php if ( has_post_thumbnail() && ! generate_show_title()) { // Do your breadcrumb stuff here } ?>
July 10, 2020 at 10:35 am #1359399StevenThanks, David. Not sure what is conflicting. We do have some filters in our functions.php that modify the breadcrumbs so maybe that action is interfering with the generate_hook filter. Your suggestion to add PHP directly to the element seems to be working. Here’s what we went with since we really only need the breadcrumb hidden when the title is suppressed:
<?php $start = '<div id="cob-breadcrumb-header" aria-label="You are here breadcrumb navigation"><i class="fas fa-home"></i> '; $breadcrumb = '[wpseo_breadcrumb]'; $end = '</div>'; if ( generate_show_title()) { echo $start . $breadcrumb . $end ; } ?>
Note: BB edit seems to be suppressing the shortcode added to the $breadcrumb variable. It should be:
$breadcrumb = ‘left bracket shortcode right bracket‘;
July 10, 2020 at 12:25 pm #1359463DavidStaffCustomer SupportGlad to hear that. And thanks for sharing your code 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.