Site logo

Archived topic

Hiding breadcrumb when hero is disabled

7 replies · Started by Steven on July 2, 2020

Viewing posts 1–8 of 8

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.

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 );

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() ) {

}

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 );

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 
}
?>

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 = '[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';

Glad to hear that. And thanks for sharing your code :)

This archived topic is closed to new replies.