Skip to content

Breadcrumbs

Ben Gillbanks edited this page Sep 11, 2019 · 5 revisions

Display breadcrumbs on your posts, and categories.

This module needs two things to work:

  1. It needs to be enabled in the Toolbelt Settings
  2. It needs to be implemented in the theme.

Why enabled in the settings AND implemented in the theme?

To keep speed high, Toolbelt only includes code for enabled modules. The breadcrumbs only work when the tb_breadcrumbs function is called, but the function will not exist without the module being enabled.

In addition, by having a setting; themes that add support for breadcrumbs can still disable them whilst using other Toolbelt features.

Implementation

To add to a theme I would suggest creating a new template function that looks something like:

function my_theme_breadcrumbs() {
    if ( function_exists( 'toolbelt_breadcrumbs' ) ) {
        toolbelt_breadcrumbs();
    }
}

This reduces the likelihood of things breaking. If Toolbelt gets deleted, or the module disabled, then no errors will appear and the site will continue to work.

Filters

toolbelt_display_breadcrumbs

This filter allows you to hide the breadcrumbs on certain post or taxonomy types.

By default the value is false and breadcrumbs will be displayed if appropriate. Return true to hide the breadcrumbs.

For example to hide the breadcrumbs on pages, but show them everywhere else you could use:

function my_diplay_breadcrumbs() {
    if ( is_page() ) {
        return false;
    }
    return true;
}
add_filter( 'toolbelt_display_breadcrumbs', 'my_diplay_breadcrumbs' ); 
You can’t perform that action at this time.