Skip to content

Instantly share code, notes, and snippets.

@craigsimps
Created March 15, 2018 14:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save craigsimps/916b23febdd8fcc0b5d389b1cc5f5f79 to your computer and use it in GitHub Desktop.
Save craigsimps/916b23febdd8fcc0b5d389b1cc5f5f79 to your computer and use it in GitHub Desktop.
<?php
add_action( 'bcn_after_fill', 'project_rebuild_breadcrumb' );
/**
* Rebuild the breadcrumb created by Breadcrumb NavXT.
*
* @param bcn_breadcrumb_trail $breadcrumb Instance of the currently active breadcrumb trail.
*/
function project_rebuild_breadcrumbs( $breadcrumb ) {
if ( ! is_singular( [ 'case-studies', 'articles', 'presentations', 'papers-reports', 'creative-portfolio' ] ) ) {
return;
}
// Default breadcrumb template.
$breadcrumb_template = '<span class="breadcrumb-link-wrap" itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem" property="itemListElement" typeof="ListItem"><a itemprop="item" property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>';
/**
* Store the first and last breadcrumbs, we're rebuilding the middle part.
*/
$breadcrumb_root = reset( $breadcrumb->breadcrumbs );
$breadcrumb_end = end( $breadcrumb->breadcrumbs );
/**
* Build our custom Knowledge breadcrumb.
*/
$knowledge_page = get_page_by_path( 'knowledge' );
$breadcrumb_title = __( 'Knowledge', 'project' );
$breadcrumb_link = get_the_permalink( $knowledge_page->ID );
$knowledge_item_breadcrumb = new bcn_breadcrumb( $breadcrumb_title, $breadcrumb_template, [], $breadcrumb_link, $knowledge_page->ID );
/**
* Update the Breadcrumb NavXT object.
*/
$breadcrumb->breadcrumbs = [
$breadcrumb_root,
$knowledge_item_breadcrumb,
$breadcrumb_end,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment