Skip to content

PHP class that will allow you to get a list of breadcrumb elements and display them in any html you want.

Notifications You must be signed in to change notification settings

levenyatko/wp-breadcrumbs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Breadcrumbs for Wordpress developers

What is this?

This is a PHP class that will allow you to get a list of breadcrumb elements and display them in any html you want.

Usage Example

Base usage

Place the LevDBreadcrumbsData.php file in your theme or plugin.

Include the file.

Create an instance of the class and call the build() method.

$crumbs = new LevDBreadcrumbsData();
$crumbs_items = $crumbs->build($args);

Output the data

if ( ! empty($crumbs) ) {
    echo '<ul itemscope itemtype="https://schema.org/BreadcrumbList">';
    foreach ($crumbs as $i => $crumb) {
        if ( empty($crumb['url']) ) {
            echo '<li>';
            echo '<span class="current">';
            echo '<span>' . $crumb['title'] . '</span>';
            echo '</span>';
            echo '</li>';
        } else {
            echo '<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">';
            echo '<a itemprop="item" href="' . $crumb['url'] . '">';
            echo '<span itemprop="name">' . $crumb['title'] . '</span>';
            echo '</a>';
            echo '<meta itemprop="position" content="' . ($i+1) . '" />';
            echo '</li>';
        }
    }
    echo '</ul>';
}

Advanced

You can change labels, custom post type archive page or breadcrumbs taxonomy

$args = [
    'show_paged' => 0, // hide breadcrumb with page number
    'labels' => [
        'search' => 'Search: "%s"',
    ],
    'post_terms' => [
         'movie' => 'genre',
    ],
    'archive_pages' => [
        'movie' => 1111, // archive page ID
    ]
];
$crumbs = new LevDBreadcrumbsData();
$crumbs_items = $crumbs->build($args);

About

PHP class that will allow you to get a list of breadcrumb elements and display them in any html you want.

Topics

Resources

Stars

Watchers

Forks

Languages