Add Custom Links to the Breadcrumbs Trail
Important
This snippet is specifically for the theme's breadcrumbs. If you are using a plugin like Yoast SEO, you will need to use a different snippet or disable the Yoast breadcrumbs and use the theme's breadcrumbs instead.
The following snippet can be used to insert items into the theme's breadcrumbs trail.
/**
* Insert a new link after the Home link in breadcrumbs for portfolio items only.
*/
add_filter( 'wpex_breadcrumbs_trail', function( $trail ) {
// Add a new link to the breadcrumbs for portfolio items
// change this conditional to fit your needs!
if ( is_singular( 'portfolio' ) ) {
// Save backup of original trail
$og_trail = $trail;
// Change the offset of where you want the new item to be added
$offset = 1;
// Your new item html
$new_item = '<a href="YOUR LINK"><span>YOUR LINK TEXT</span></a>';
// Add new item into the trail at given offset
$trail = array_slice( $og_trail, 0, $offset, true ) + [
'new_item' => $new_item,
] + array_slice( $og_trail, $offset, NULL, true);
}
// Return crums trail
return $trail;
} );All PHP snippets should be added via child theme's functions.php file or via a plugin.
We recommend Code Snippets (100% Free) or WPCode (sponsored)
We recommend Code Snippets (100% Free) or WPCode (sponsored)
Related Snippets