Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Breadcrumbs on Search Results Screen

@robin-w

Moderator

that was an interesting challenge, as the forum ID is not known when the breadcrumbs start to show, so I had to look up the forum_id from the first result.

but this should work, just add it to your functions file

add_filter ('bbp_breadcrumbs' , 'rew_breadcrumb_search' ) ;

function rew_breadcrumb_search ($crumbs) {
	//create a new array
	$new_crumbs = array() ;
	//find the forum from the first item in results
	if ( bbp_has_search_results()) {
		while ( bbp_search_results() ) : bbp_the_search_result(); 
		$type = get_post_type() ;
		if ($type == 'topic' ) $forum_id = bbp_get_topic_forum_id() ;
		if ($type == 'reply' ) $forum_id = bbp_get_reply_forum_id() ;
		if (!empty ($forum_id)) break ;
		endwhile ;
	}
	//cycle through the crumbs until we find search
	foreach ($crumbs as $crumb=>$data) {
		if (strpos($data, 'search') !== false) {
			//If the forum ID exits, add the breadcrumb
			if( $forum_id && is_numeric( $forum_id ) ){
				$new_crumbs[] = '<a href="' . esc_url( bbp_get_forum_permalink( $forum_id ) ) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title($forum_id ) . '</a>';
			}
		}
		$new_crumbs[] = $data ;
	}
return $new_crumbs ;
}
Skip to toolbar