Calling the Breadcrumb Trail

There are several ways of calling Breadcrumb NavXT’s breadcrumb trail. The first decision is between using the included widget, or calling one of the bcn_display* functions. This guide covers some examples for calling the breadcrumb trail using the bcn_display() function.

Traditional/Basic

The most basic way of calling the breadcrumb trail is simply calling the bcn_display() function. This is the old default calling method that dates back 9 years. As a matter of good practice, prior to calling this function, its existence should be checked. Below is an example of the bare minimum calling code:

<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>

Default (Schema.org BreadcrumbList support)

While the basic calling code will generate a breadcrumb trail, it will not be Schema.org BreadcrumbList compliant. Simply adding the appropriate HTML around the basic code brings the trail up to BreadcrumbList compliance (using the default settings the individual breadcrumbs are already compliant, see How to Implement Schema.org BreadcrumbList with Breadcrumb NavXT). Below is an example of Schema.org BreadcrumbList compatible calling code:

<div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">
<?php
if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div>

Exclude Some Pages

Suppose you do not want the breadcrumb trail to be displayed on one or more pages (page, posts, or anything that is determinable via a WordPress Conditional Tag), for the basic usage, just add the check into the if statement. Remember that you are checking the inverse of a conditional tag, thus should use the AND operation to combine checks of conditional tags. Below is an example of using inversion and the AND operation to exclude the breadcrumb trail from two pages (with IDs PAGE_ID1 and PAGE_ID2):

<?php if(function_exists('bcn_display') && !is_page(PAGE_ID1) && !is_page(PAGE_ID2))
{
bcn_display();
}?>

Some find the above construct unnatural, and would prefer to use OR operations. Using De Morgan’s Law, the above can be translated to:

<?php if(function_exists('bcn_display') && !(is_page(PAGE_ID1) || is_page(PAGE_ID2)))
{
bcn_display();
}?>

Exclude Some Pages–Advanced

While the above examples for excluding the Breadcrumb trail on a page or two work, they may not be optimal if the breadcrumb trail is surrounded by a specific HTML tag that does not make sense without the breadcrumbs within it. An example would be the default usage covered above. Without the breadcrumbs, the surrounding DIV does not really make sense. Below is an example of excluding the breadcrumb trail from two pages (with IDs PAGE_ID1 and PAGE_ID2) that will not output any HTML if the breadcrumb trail is not being displayed:

<?php if(function_exists('bcn_display') && !is_page(PAGE_ID1) && !is_page(PAGE_ID2)):?>
<div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">
<?php bcn_display();?>
</div>
<?php endif; ?>

The above are just a few examples of how Breadcrumb NavXT’s breadcrumb trail can be called. Note that the bcn_display() function also accepts three parameters. See the Breadcrumb NavXT Documentation for more information on bcn_display().

-John Havlik

[end of transmission, stay tuned]

19 thoughts on “Calling the Breadcrumb Trail

  1. Hi John,
    Thanks for your great plugin. How do I go about if I don’t want a specific page to be in the breadcrumbtrail? In below url it’s the Product together with the pipe symbol I don’t want to show.

    Kind regards,
    Cor Claessen

    • Can you elaborate more on what you mean by “not working”? Is the breadcrumb trail never showing up? Or, is the breadcrumb trail not being excluded from the desired pages?

      -John Havlik

  2. Hello please could you confirm where I should add the code traditional/Basic?
    I mean which file I should chose to show breadcrumbs on all URLs and on between header and article/page/category page/ tag page. Thanks in an advance for your answer.

  3. Hi there

    I use this plugin on my site, but is there also a shortcode [] one can use?
    I wish to put shortcode in widget and do it like that as wordpress keeps on removing the code in header.php? Many thanks!

    regards Katy

    • Hi Katharine,

      If WordPress keeps removing the code from header.php, it’s likely the theme you are using is getting updated, and the updates are wiping out the call. You can look into creating a child theme, with it’s own header.php file. Or, depending on your theme, there may be an action or filter for the correct area to place a breadcrumb trail and you can write a hook into said action/filter that calls bcn_display(). Just be sure to place that filter/action hook in a site specific plugin so that future theme updates don’t wipe it out.

      Breadcrumb NavXT ships with a widget and a Gutenberg block, between those two most situations should be covered. Since shortcodes have been deprecated within WordPress core, my current position is to not include one in Breadcrumb NavXT itself. A shortcode is available in the Breadcrumb NavXT uManager premium add-on plugin. Otherwise, you could always create your own shortcode (via code in a site specific plugin) that calls bcn_display().

      -John Havlik

  4. I am only getting the home page and the current page in my breadcrumbs. None of the parent pages show up between these breadcrumbs.
    I am calling the breadcrumb code from the header.php file.

    • Hi John,

      The first place to check is the child pages, ensure they have a parent page set. Keep in mind, that any relationship established via the WordPress menu editor does not reflect the actual location of/relationship between pages/posts and Breadcrumb NavXT, by default, only follows the actual location of/relationship between pages/posts.

      If you’re dead set on using only the menu for content organization, you can use Breadcrumb NavXT Menu Magic which helps Breadcrumb NavXT follow the relationships established in the menu. However, that probably is not necessary.

      -John Havlik

Leave a Reply

Your email address will not be published. Required fields are marked *