Created
April 23, 2019 08:51
-
-
Save kisildev/a7bf28070ef45c6a0f5f078f3335ed86 to your computer and use it in GitHub Desktop.
Custom Breadcrumbs NavXT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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