[Resolved] Hiding breadcrumb when hero is disabled

Home Forums Support Hiding breadcrumb when hero is disabled

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1350092
    Steven

    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.

    #1350416
    David
    Staff
    Customer Support

    Hi there,

    if the Breadcrumb is added using a Hook you would use the generate_hook_element_display filter

    https://docs.generatepress.com/article/generate_hook_element_display/

    And your function would use the same conditional logic as your current header element function.

    #1355671
    Steven

    Hmmm…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 );
    #1355807
    Tom
    Lead Developer
    Lead Developer

    Hmm, 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() ) {
    
    }
    #1355829
    Steven

    Tried 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 );
    #1356244
    David
    Staff
    Customer Support

    I 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 
    }
    ?>
    #1359399
    Steven

    Thanks, 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 = '';
    $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‘;

    #1359463
    David
    Staff
    Customer Support

    Glad to hear that. And thanks for sharing your code 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.