Breadcrumbs gives you a function, wpc_get_breadcrumbs(), that returns an SEO-friendly breadcrumb
trail (with schema.org markup for rich results) for the current page.
Enabling
Turn on Tools → Site Tools → Enable Breadcrumbs. The wpc_get_breadcrumbs() function only exists
while that toggle is on.
Usage
The function returns the HTML (it doesn’t print it), so echo it:
// In a theme template:
echo wpc_get_breadcrumbs();
// In a WP Coder snippet's PHP tab:
echo wpc_get_breadcrumbs();
// With custom options:
echo wpc_get_breadcrumbs( [
'separator' => '/',
'taxonomy' => 'product_cat',
'label_home' => 'Start',
] );
On the front page it returns an empty string (no trail is shown there).
Options
Pass an array to wpc_get_breadcrumbs( $args ). Defaults:
| Option | Default | Purpose |
|---|---|---|
class-ol |
breadcrumbs |
CSS class on the wrapping <ol>. |
class-li |
breadcrumb |
CSS class on each item. |
class-link |
breadcrumb__link |
CSS class on each link. |
class-current |
breadcrumb__current |
Extra class on the current-page item. |
class-separator |
breadcrumb__separator |
CSS class on the separator. |
separator |
‣ |
Markup between items. |
taxonomy |
category |
Which taxonomy supplies the term trail on single posts (e.g. product_cat). |
display_current |
true |
Whether to show the current page as the last crumb. |
label_home |
Home |
Label for the first (home) crumb. |
label_search |
Search Results for "%s" |
Current-crumb label on search results. |
label_404 |
Page not found |
Current-crumb label on 404 pages. |
⚠ To hide the current crumb, pass 'display_current' => 'false'.
⚠ No CSS is bundled — style the trail yourself using the classes above.
What the trail contains
| Context | Trail |
|---|---|
| Front page | (empty) |
| Blog posts page | Home → current page title |
| Post type archive | Home → archive title |
| Single post/page | Home → archive → parent pages → first term + ancestors → current title |
| Category / Tag / taxonomy | Home → archive → term ancestors → current term |
| Search results | Home → “Search Results for …” |
| 404 | Home → “Page not found” |
| Author archive | Home → author name |
| Date archive | Home → year (→ month) → current |
For developers
Two filters let you customize the output:
| Filter | What it changes |
|---|---|
wpcoder_breadcrumbs_args |
The options array before the trail is built. |
wpcoder_breadcrumbs_links |
The array of link crumbs before output (to insert or remove items). |
add_filter( 'wpcoder_breadcrumbs_args', function ( $args ) {
$args['separator'] = '›';
$args['label_home'] = 'Home page';
return $args;
} );