Last active
December 23, 2021 23:10
-
-
Save GaryJones/283f2e90caa1deb51f23 to your computer and use it in GitHub Desktop.
Wrap the last Genesis breadcrumb in a span for styling.
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_filter( 'genesis_build_crumbs', 'gj_wrap_last_breadcrumb', 10, 2 ); | |
/** | |
* Wrap the last Genesis breadcrumb in a span for styling. | |
* | |
* @author Gary Jones | |
* | |
* @param array $crumbs Existing HTML markup for the breadcrumbs. | |
* | |
* @return array Amended HTML markup for the breadcrumbs. | |
*/ | |
function gj_wrap_last_breadcrumb( $crumbs, $args ) { | |
// Ensure duplicate and empty crumb entries are handled. | |
$crumbs = array_filter( array_unique( $crumbs ) ); | |
$last_crumb_index = count( $crumbs ) - 1; | |
// Some "crumbs" actually contain multiple separated crumbs (i.e. sub-pages) | |
// so make sure we're really only getting the last separated crumb | |
$crumb_parts = explode( $args['sep'], $crumbs[ $last_crumb_index ] ); | |
if ( count( $crumb_parts ) > 1 ) { | |
$last_crumb_part_index = count( $crumb_parts ) - 1; | |
$crumb_parts[ $last_crumb_part_index ] = '<span class="last-breadcrumb">' . $crumb_parts[ $last_crumb_part_index ] . '</span>'; | |
$crumbs[ $last_crumb_index ] = join( $args['sep'], $crumb_parts ); | |
} else { | |
$crumbs[ $last_crumb_index ] = '<span class="last-breadcrumb">' . $crumbs[ $last_crumb_index ] . '</span>'; | |
} | |
return $crumbs; | |
} |
Thanks! This saved me a lot of time and trouble!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great! Thank you a lot for shearing!