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]

9 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

Leave a Reply

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