0

Can anyone help me to hide breadcrumbs from certain page ID's?

I'm using the Breadcrumb NavXT plugin. I've only found out how to hide it from the home page.

I'm using this code in my header.php:

if ( ! is_front_page() ) {
    bcn_display();
}

1 Answer 1

1

Suppose you have set up an array of page IDs where you don't want the breadcrumbs to be displayed.

$ids = array( 4, 8, 15, 16, 23, 42 );

Now you just have to check if the currently displayed page (or post) has one of these IDs, and if not, display the breadcrumbs.

if ( ! in_array( get_the_ID(), $ids ) ) {
    bcn_display();
}

// EDIT
And if you want to exclude pages only—no other (custom) posts—you could speed up the check a bit.

if (
    ! is_page()
    || ! in_array( get_the_ID(), $ids )
) {
    bcn_display();
}

// EDIT (as per your comment)
To exclude the front page as well as specific pages, try this:

$ids = array( 4, 8, 15, 16, 23, 42 );
// Automagically add the ID of your front page
$ids[ ] = (int) get_option( 'page_on_front' );

if (
    ! is_page()
    || ! in_array( get_the_ID(), $ids )
) {
    bcn_display();
}
2
  • Thanks for this, that's great. Do I put the first bit within the same php tags? And should I exclude the home page by ID or combine the two?
    – RexTheRunt
    Commented Dec 8, 2014 at 17:22
  • @RexTheRunt Please see my edit. There are several ways to do what you want. For instance, use is_front_page, or get the front page ID (see my answer).
    – tfrommen
    Commented Dec 8, 2014 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.