Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Last active December 23, 2021 23:10
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GaryJones/283f2e90caa1deb51f23 to your computer and use it in GitHub Desktop.
Save GaryJones/283f2e90caa1deb51f23 to your computer and use it in GitHub Desktop.
Wrap the last Genesis breadcrumb in a span for styling.
<?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;
}
@OksanaRomaniv
Copy link

Great! Thank you a lot for shearing!

@makeworthymedia
Copy link

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