How to Add a Custom Breadcrumb Template Tag

Since version 4.4.0, it has been possible to add additional custom template tags to supplement the defaults included in Breadcrumb NavXT. Adding a custom template tag is relatively easy. All one has to do is write a function that hooks into the bcn_template_tags filter and adds the new template tag.

bcn_template_tags has three parameters, two for helping identify the resource the breadcrumb represents, and one for the actual replacement set. Today, we’ll focus on the first parameter, the $replacements array. This associative array has the template tag as the key and the value is the actual value that should replace the tag in breadcrumbs. To add a new template tag, simply add a new key-value pair to the array and return the modified $replacements array.

For example, to add a breadcrumb template tag that inserts the current theme’s directory, one could use the following:

function my_bcn_template_tag($replacements, $type, $id)
{
    //Add the %template_directory% template tag
    $replacements['%template_directory%'] = get_bloginfo('template_directory');
    //Return our new set of templates and replacements
    return $replacements;
}
add_filter('bcn_template_tags', 'my_bcn_template_tag', 3, 10);

In the code above, %template_directory% is the breadcrumb template tag being added; its value is retrieved using the get_bloginfo() function. Simple, right?

-John Havlik

[end of transmission, stay tuned]

Breadcrumb NavXT 5.5.2

This is the second, and hopefully last, bug fix release of the 5.5 branch of Breadcrumb NavXT. One bug was fixed in this release. Breadcrumb NavXT 5.5.0 introduced a bug where the “blog breadcrumb” setting did not affect the generated breadcrumb trail.

The code that checked the blog_display setting was removed in a cleanup of bcn_breadcrumb_trail::do_root() and bcn_breadcrumb_trail::find_type() in 5.5.0. This functionality has been re-implemented in 5.5.2. Additionally, as part of an ongoing effort to add automated testing for Breadcrumb NavXT, unit tests were added to capture this bug (should further changes to do_root() and find_type() cause it to reappear.

As always, you can grab the latest version of Breadcrumb NavXT from the Breadcrumb NavXT page. If you experience any issues with this version of Breadcrumb NavXT, please leave a comment on this post detailing the issue.

-John Havlik

[end of transmission, stay tuned]

Breadcrumb NavXT Paths 1.0.0

Introducing Breadcrumb NavXT Paths. This plugin adds support for “structured” path breadcrumb trails. The user path to a post with multiple terms in the same taxonomy will influence the terms displayed in the breadcrumb trail. As the the successor of Order Bender, it also features the ability to specify a preferred term when a post is a member of multiple terms within a taxonomy.

Features

  • Automatically selects the term hierarchy for a post based off of the user’s previously visited term archive
  • Supports picking the term based off of the “Preferred” term for the post in Yoast SEO
  • Includes “Preferred Term” metabox in the post editor for setting the preferred term if none of the supported SEO plugins are active

-John Havlik

[end of transmission, stay tuned]

Breadcrumb NavXT 5.5.1

This is the first, and hopefully only, bug fix release of the 5.5 branch of Breadcrumb NavXT. One bug was fixed in this release. Breadcrumb NavXT 5.5.0 introduced a bug on sites that use static front pages.

On sub-pages (of the page post type), a breadcrumb representing the page for posts would be erroneously included in the breadcrumb trail. This was due to a bug in bcn_breadcrumb_trail::find_type() that identified pages as posts. Previously, this did not cause a problem due to redundant code in bcn_breadcrumb_trail::do_root(). That code was removed in a cleanup of bcn_breadcrumb_trail::do_root() in 5.5.0. As part of an ongoing effort to add automated testing for Breadcrumb NavXT, unit tests were added to capture this bug (should further changes to do_root() cause it to reappear.

As always, you can grab the latest version of Breadcrumb NavXT from the Breadcrumb NavXT page. If you experience any issues with this version of Breadcrumb NavXT, please leave a comment on this post detailing the issue.

-John Havlik

[end of transmission, stay tuned]

Breadcrumb NavXT 5.5.0

Holy HTTP referer influenced taxonomy selection Batman! The oft-requested, and quite delayed feature finally made it into Breadcrumb NavXT with the release of version 5.5.0. For the breadcrumb templates, translate, and lang were added as acceptable attributes for most HTML tags supported. Additionally, scrset, and sizes were added as acceptable attributes for img tags. Finally, itemprop was added as an approved attribute for meta tags.

Two bugs were squashed in this release. The first bug involves working around 3rd party plugins that modify the post type of the $post global. The second resolves a bug where a custom post type did not have a root page set, Breadcrumb NavXT could end up incorrectly using the root page for the Post post type. Finally, there are a couple of behavior changes to note for how a taxonomy term is selected for a post (when the post is a member of multiple terms for the same taxonomy) and for users of date and post parent hierarchies.

Behavior Changes

The internal mechanisms for handling date and post parents as the hierarchy for a post type has changed. In the past, these were represented by having the taxonomy_type option for the post type set to ‘date’ for a date based hierarchy and ‘page’ for a post parent based hierarchy. They are now represented by the values ‘BCN_DATE’ and ‘BCN_POST_PARENT’. This is the first step in some internal cleanup for settings that have changed meaning since their original introduction. If you are using either a date based hierarchy, or a post parent based hierarchy, you will need to visit the Breadcrumb NavXT settings page and migrate the settings.

Additionally, the behavior of bcn_breadcrumb_trail::pick_post_term() has changed. In the past, it would return the first term for the post in question that had a parent term. This has changed to picking the deepest known child of the first hierarchy found in the list terms for the post in question. Note users of Order Bender, you will need to upgrade to Order Bender 0.7.0 (or newer) since previous versions relied on the old behavior of bcn_breadcrumb_trail::pick_post_term().

Translations

As explained in the Breadcrumb NavXT Translations Moving to Language Packs article, Breadcrumb NavXT has moved away from shipping translations with the plugin. This is the first release to ship without any included translations, all translations are available via language packs, or from the Breadcrumb NavXT Translation Project.

If you would like to contribute to translating Breadcrumb NavXT, please visit the Breadcrumb NavXT Translation Project. A big thanks to all of the translators that have contributed to the translations in the past and continue to contribute.

As always, you can grab the latest version of Breadcrumb NavXT from the Breadcrumb NavXT page. If you experience any issues with this version of Breadcrumb NavXT, please leave a comment on this post detailing the issue.

-John Havlik

[end of transmission, stay tuned]