2017 © Pedro Peláez
 

library wp-crumbs

Simple Wordpress Breadcrumbs.

image

jjgrainger/wp-crumbs

Simple Wordpress Breadcrumbs.

  • Thursday, October 26, 2017
  • by jjgrainger
  • Repository
  • 3 Watchers
  • 17 Stars
  • 422 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 0 Open issues
  • 4 Versions
  • 5 % Grown

The README.md

WP Crumbs v1.0.2

Simple Wordpress Breadcrumbs, (*1)

Build Status Total Downloads Latest Stable Version License, (*2)

Requirements

Installation

$ composer require jjgrainger/wp-crumbs

Usage

Basic usage

Use the_crumbs to display the breadcrumbs in your template., (*3)

the_crumbs();

Options

An optional array of arguments can be passed to modify the breadcrumb output. The defaults for each option are display below., (*4)

Example
the_crumbs( [
    'home'      => 'Home',   // Title for the Home (front page) link
    'blog'      => 'Blog',   // Title for the blog home page
    'seperator' => '/',      // Seperator to use between each crumb (string or false)
    'class'     => 'crumbs', // The class(es) applied to the wrapper element ('crumbs', 'nav crumbs')
    'element'   => 'nav'     // The HTML element to use (div, nav, ol, ul)
] );
Output
<nav class="crumbs">
    <a href="http://site.com/">Home</a>
    <span class="sep">/</span>
    <a href="http://site.com/blog/">Blog</a>
    <span class="sep">/</span>
    <span>Single Post Title</a>
</nav>

Advanced usage

get_crumbs()

Use get_crumbs() to retrieve an array of crumbs. Each crumb has a title and url., (*5)

Example
$breadcrumbs = get_crumbs();

print_r( $breadcrumbs );
Output
Array(
    [0] => Array(
        [title] => "Home"
        [url] => "http://site.com/"
    )
    [1] => Array(
        [title] => "Blog"
        [url] => "http://site.com/blog/"
    )
    [2] => Array(
        [title] => "My First Post"
        [url] => false
    )
)

You can modify the returned array and/or create a function to create an output of your choosing., (*6)

get_crumbs accepts the same aguments as the_crumbs., (*7)

Filters

You can further modify the crumbs array using a filter on get_crumbs. This will also effect the output of the_crumbs., (*8)

Example

// Example: modify title for a custom post type function modify_crumbs( $crumbs ) { // if on events archive change title to shows if ( is_post_type_archive( 'event' ) || is_singular( 'event' ) ) { for ( $i = 0; $i < count($crumbs); $i++ ) { if ( $crumbs[$i]['title'] === 'Events' ) { $crumbs[$i]['title'] = "Shows"; } } } return $crumbs; } add_filter( 'get_crumbs', 'modify_crumbs' );

array_insert()

array_insert() is a function that allows you to insert a new element into an array at a specific index. You can see a gist of it here., (*9)

when modifying the crumb trail you can add new crumbs at specific points., (*10)

Example
// Example: add post type archive on taxonomy archive page
function modify_crumbs( $crumbs ) {
    // if on the events category archive page
    if ( is_tax( 'event-categories' ) ) {
        // create a new crumb
        $crumb = [
            'title' => "Shows",
            'url'   => site_url( '/shows' ),
        ];

        // add the new crumb at the index of 1
        $crumbs = array_insert( $crumbs, $crumb, 1 );
    }

    return $crumbs;
}

add_filter( 'get_crumbs', 'modify_crumbs' );

Notes

Author

Joe Grainger, (*11)

The Versions

26/10 2017

dev-master

9999999-dev https://github.com/jjgrainger/wp-crumbs

Simple Wordpress Breadcrumbs.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

22/01 2015

v1.0.2

1.0.2.0 https://github.com/jjgrainger/wp-crumbs

Simple Wordpress Breadcrumbs.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

17/12 2014

v1.0.1

1.0.1.0 https://github.com/jjgrainger/wp-crumbs

Simple Wordpress Breadcrumbs.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

25/10 2014

v1.0.0

1.0.0.0 https://github.com/jjgrainger/wp-crumbs

Simple Wordpress Breadcrumbs.

  Sources   Download

MIT

The Requires

  • php >=5.3.0