arraypress / wp-breadcrumbs
A lightweight fluent builder for generating accessible HTML breadcrumb navigation with Schema.org microdata, ARIA attributes, and WordPress admin support.
Requires
- php: >=8.3
Requires (Dev)
- phpcompatibility/phpcompatibility-wp: ^2.1
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.13.5
- wp-coding-standards/wpcs: ^3.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This library has moved. It is now part of
sugarcommerce/breadcrumbs(namespaceSugarCommerce\Breadcrumbs, PHP 8.3+). That package's README has a "Moving from arraypress/wp-*" table. This repository is archived and read-only.
Breadcrumbs
Build a breadcrumb trail that search engines can read and screen readers can navigate.
What it does
Breadcrumbs look like a list of links until you need them done properly: a
<nav> with a label, the current page marked with aria-current rather than
just styled differently, and Schema.org microdata so Google shows the trail
in results instead of a bare URL.
This builds that markup from the items you add, so the accessibility and the structured data come for free rather than being remembered.
Features
- Build a trail by adding items, with the current page marked correctly
- Get Schema.org BreadcrumbList microdata without writing any of it
- Mark the current item with
aria-current, not just a CSS class - Add an icon to any item: a Heroicon, a Dashicon, or your own markup
- Set your own classes on the nav, the list, the items and the separator
- Render from an array, when the trail is already assembled elsewhere
Installation
composer require arraypress/wp-breadcrumbs
Quick start
use ArrayPress\Breadcrumbs\Breadcrumbs; Breadcrumbs::create() ->add( 'Home', '/', 'heroicons-outline:home' ) ->add( 'Products', '/products/' ) ->add_current( 'Widget Pro' ) ->display();
add_current() rather than a third add() — the last crumb is the page you
are on, so it is not a link and is announced as the current one.
When the trail already exists as data:
echo render_breadcrumbs( [ [ 'label' => 'Home', 'url' => '/' ], [ 'label' => 'Blog', 'url' => '/blog/' ], [ 'label' => 'This post' ], ] );
Icons
The third argument to add(), add_home() and add_current(), and the
icon key of an item array, takes any of:
set:name--heroicons-outline:home,heroicons-solid:folder-- drawn as inline SVG incurrentColor, 20 by 20, aligned as a Dashicon is- a Dashicons name, bare or as the class --
admin-homeordashicons-admin-home-- drawn as the font's span, as before - anything else, printed as given (raw HTML, so never untrusted input)
Both named forms carry the class arraypress-icon, so one rule sizes either:
.my-trail .arraypress-icon { width: 16px; height: 16px; font-size: 16px; }
set:name icons are drawn by arraypress/wp-field-kit, which is suggested
rather than required. Without it a Dashicons name still draws and a
set:name icon draws nothing.
Requirements
- PHP 8.3 or later
- WordPress 7.1 or later
arraypress/wp-field-kit(optional), forset:nameicons
License
GPL-2.0-or-later