Skip to content

Snippet: Add Links to the Breadcrumbs Trail

function myprefix_add_custom_link_to_breadcrumbs( $trail ) {

	// Add a new link to the breadcrumbs for portfolio items
	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" title="YOUR LINK TITLE"><span>YOUR LINK TEXT</span></a>';

		// Add new item into the trail at given offset
		$trail = array_slice( $og_trail, 0, $offset, true ) + array(
			'new_item' => $new_item,
		) + array_slice( $og_trail, $offset, NULL, true);


	// Return crums trail
	return $trail;
add_filter( 'wpex_breadcrumbs_trail', 'myprefix_add_custom_link_to_breadcrumbs' );
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)
Back To Top