If you are on a multisite install, each profile has a tab containing a list of sites the member belongs too, so those link already exist.
If you want such link elsewhere, you basically can use this.
As you say nothing about where you want the link to be on a profile, i assume you want it explicitly showing on the profile header. Following snippet will accomplish that. I tested it on a MS install with 2 blogs (main site + 1 user blog).
function my_link_to_blog() {
if ( bp_is_user() ) {
$user_id = bp_displayed_user_id();
} else {
$user_id = bp_get_member_user_id();
}
$blogs = get_blogs_of_user( $user_id );
if ( $blogs ) {
echo '<ul>';
foreach ( $blogs as $blog ) {
// exclude the main blog if a user signed to another one
if ( $blog->userblog_id != get_current_blog_id() ) {
echo '<li>View my blog<a href="http://' . $blog->domain . $blog->path .'">' . $blog->blogname . '</a></li>';
}
}
echo '</ul>';
}
}
add_action( 'bp_before_member_header_meta' , 'my_link_to_blog' );
Add to bp-custom.php
Hello @danbp I used the code that you gave me, however it created a list of my blogs rather than pointing me back to the original blog I signed in with. Any ideas?
Thanks
Which WP install type are you using ? MS or single ? Give details please.
Its an MU install. After much thought — what you came up with is much better than what I was imagining — thanks for that. One more thing, is it possible to display those blogs only to the user and not other people who visit their profile?
Thanks
Yep ! Use fn bp_is_my_profile()
For ex. something like if ( $blogs && bp_is_my_profile() ) {
Awesome thank you.
Confirmed Resolved