Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using Yoast's Wordpress SEO plugin to generate breadcrumbs for my site. The problem is that when it comes to BuddyPress pages, the breadcrumbs can't see a member's profile page. Right now it shows "Home > Members" on the profile page when it should "Home > Members > Whatever the member's name is".

Here's a snpashot of what I mean

enter image description here

Thanks to @brasofilo I was able to get it. Here's my final code

add_filter( 'wpseo_breadcrumb_links', 'fix_bp_prifile_bc', 10, 2 );
function fix_bp_prifile_bc( $links ) {
    global $bp;
    $user_info = bp_get_user_meta( $bp->displayed_user->id, 'nickname', true );
    //check if we are viewing the profile  
    if($user_info):
        $links[] = array( 'url' =>'', 'text' =>$user_info );
    endif;
    return $links;
}
share|improve this question

closed as off-topic by toscho Aug 2 at 20:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 2 down vote accepted

This is possible using the filter wpseo_breadcrumb_links.

In this example, I'm using the functions bp_get_user_meta and bp_loggedin_user_id, adjust as needed.

To check if the page is child of the Members page (in this example, ID == 2), I'm using the function has_parent grabbed from here.

add_filter( 'wpseo_breadcrumb_links', 'buddy_crumbs_wpse_88889' );

function buddy_crumbs_wpse_88889( $links )
{
    // apply only in childs of Members page
    // in this example, Members has the ID of 2
    global $post;
    if( !has_parent_wpse_88889( $post, 2 ) )
        return $links;

    $user_info = bp_get_user_meta( bp_loggedin_user_id(), 'nickname', true );
    $links[] = array( 'url' => '', 'text' => $user_info );
    return $links;
}

function has_parent_wpse_88889($post, $post_id) 
{
    if ( $post->ID == $post_id ) 
        return true;
    else if ( $post->post_parent == 0 ) 
        return false;
    else 
        return has_parent_wpse_88889( get_post( $post->post_parent ), $post_id );
}

buddypress members breadcrumb

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.