A powerful script for adding breadcrumbs to your site that supports Schema.org, HTML5-valid microdata.
Breadcrumb Trail is one of the most advanced and robust breadcrumb menu systems available for WordPress. It started out as a small script for basic blogs but has grown into a system that can handle nearly any site's setup to show the most accurate breadcrumbs for each page.
This script won't work automatically because there's no way for me to know where it should show within your theme. You'll have to add it manually in your template files. You can add it pretty much anywhere you want, but I usually recommend near the bottom of your theme's
The basic code you need is:
<?php breadcrumb_trail(); ?>
Actually, you should always wrap it in a
functions_exists() check too like so:
<?php if ( function_exists( 'breadcrumb_trail' ) ) breadcrumb_trail(); ?>
That's all you need to do to add breadcrumbs to your site. Of course, you can customize that a bit.
breadcrumb_trail() function accepts a single parameter of
$args, which is an array of arguments for deciding how your breadcrumbs should behave. The default arguments are the following.
$defaults = array( 'container' => 'div', // container element 'separator' => '/', // separator between items 'before' => '', // HTML to output before 'after' => '', // HTML to output after 'show_on_front' => true, // whether to show on front 'network' => false, // whether to create trail back to main site (multisite) 'show_title' => true, // whether to show the current page title 'show_browse' => true, // whether to show the "browse" text 'echo' => true, // whether to echo or return the breadcrumbs /* Post taxonomy (examples follow). */ 'post_taxonomy' => array( // 'post' => 'post_tag', // 'post' post type and 'post_tag' taxonomy // 'book' => 'genre', // 'book' post type and 'genre' taxonomy ), /* Labels for text used (see Breadcrumb_Trail::default_labels). */ 'labels' => array( 'browse' => __( 'Browse:', 'breadcrumb-trail' ), 'home' => __( 'Home', 'breadcrumb-trail' ), 'search' => __( 'Search results for "%s"', 'breadcrumb-trail' ), 'error_404' => __( '404 Not Found', 'breadcrumb-trail' ), 'paged' => __( 'Page %d', 'breadcrumb-trail' ), 'archives' => __( 'Archives', 'breadcrumb-trail' ), 'archive_minute_hour' => __( 'g:i a', 'breadcrumb-trail' ), 'archive_minute' => __( 'Minute %d', 'breadcrumb-trail' ), 'archive_hour' => __( 'g a', 'breadcrumb-trail' ), 'archive_day' => __( 'd', 'breadcrumb-trail' ), 'archive_week' => __( 'Week %d', 'breadcrumb-trail' ), 'archive_month' => __( 'F', 'breadcrumb-trail' ), 'archive_year' => __( 'Y', 'breadcrumb-trail' ), ) );
breadcrumb_trail_args- Filter hook on the array of arguments passed in.
breadcrumb_trail_items- Filter hook on the array of items before being output.
breadcrumb_trail_get_bbpress_items- Filter hook on the array of items when using bbPress.
breadcrumb_trail- Filter hook on the HTML output of the breadcrumb trail.
You can extend the
Breadcrumb_Trail class with a custom class if needed. See the
bbPress_Breadcrumb_Trail class as an example.
$items- Array of trail items.
$args- The parsed arguments passed in.
trail()- Outputs/returns the final HTML.
do_trail_items()- Method for filling the
Others are available, but those are the two you would actually put into real-world use.
- Schema.org support.
- Completely overhauled the entire plugin, rewriting large swathes of code from the ground up. This version takes an object-oriented approach.
- Blew every other breadcrumb menu script out of the water.
post_type_archive_title()on post type archives in the trail.
- Add support for taxonomies that have a
$rewrite->slugthat matches a string value for a custom post type's
- Added support for an
archive_titlelabel for custom post types because we can't use the
post_type_archive_title()function on single posts views for the post type.
- Loads of pagination support on both archive-type pages and paged single posts.
- Added support for hierarchical custom post types (get parent posts).
- Added the
networkargument to allow multisite owners to run the trail all the way back to the main site.
- Only check attachment trail if the attachment has a parent.
- Fixed the issue where the wrong post type archive link matches with a term archive page.
- No friggin' clue. I think I actually skipped version numbers somehow. :)
- Changed license from GPL 2-only to GPL 2+.
- Smarter handling of the
containerargument for wrapping breadcrumbs in a custom HTML element.
- Use hardcoded strings for the textdomain, not a variable.
- Inline doc updates.
- Added bbPress support.
get_the_title()for post titles.
get_queried_object_id()instead of accessing
$argsas second parameter in
- New function:
breadcrumb_trail_get_items(), which grabs a list of all the trail items. This separates the items from the main
- New filter hook:
breadcrumb_trail_items, which allows devs to filter just the items.
- New function:
breadcrumb_trail_map_rewrite_tags(), which maps the permalink structure tags set under Permalink Settings in the admin to make for a much more accurate breadcrumb trail.
- New function:
breadcrumb_trail_textdomain(), which can be filtered when integrating the plugin into a theme to match the theme's textdomain.
- Added functionality to handle WP 3.1 post type enhancements.
- Smarter logic in certain areas.
- Removed localization for things that shouldn't be localized with time formats.
- Better escaping of element attributes.
- Add in initial support of WordPress 3.1's post type archives.
- Better formatting and organization of the output late in the function.
trail-afterCSS classes if
- Undefined index error fixes.
- Fixes for trying to get a property of a non-object.
- Added more support for custom post types and taxonomies.
- Added more support for more complex hierarchies.
- The breadcrumb trail now recognizes more patterns with pages as part of the permalink structure of other objects.
- All post types can have any taxonomy as the leading part of the trail.
- Cleaned up the code.
- Removed and/or added (depending on the case) the extra separator item on sub-categories and date-/time-based breadcrumbs.
- The title of the "home" page (i.e. posts page) when not the front page is now properly recognized.
- Cleaned up the code and logic behind the plugin.
- Launch of the new plugin.
I run a WordPress community called Theme Hybrid, which is where I fully support all of my WordPress plugins, themes, and other projects. You can sign up for an account to get plugin support for a small yearly fee.
I know. I know. You might not want to pay for support, but just consider it a donation to the project. To continue making cool, GPL-licensed plugins/themes and having the time to support them, I must pay the bills.
Copyright and License
Breadcrumb Trail is licensed under the GNU GPL, version 2 or later.
2008 – 2013 © Justin Tadlock.