How to redirect to user profile
-
Hello.
On my website people can register via buddypress and then write blogposts via a different plugin. Everything is fine. I just want to change redirection. When you see a post and then press on its author, you see author archive. I would like to redirect to author profile on buddypress. I am not familiar with php and cannot do it by myself, but I will be able to change the code in files. Please help me with this.Thank you.
I am using WordPress 4.4.2 and buddypress Version: 2.5.1.
-
I tried to use BP Blog Author Profile Link plugin. It did not work for me
@alexandra55 you can achieve this by adding a little snippet to your bp-custom.php or functions.php.
add_action( 'template_redirect', 'themename_redirect_author_archive_to_profile' ); function themename_redirect_author_archive_to_profile() { if(is_author()){ $user_id = get_query_var( 'author' ); wp_redirect( bp_core_get_user_domain( $user_id ) ); } }
Hope this helps!
@bowromir thank you so much for your reply. Unfortunately, it did not work for me. It seems that there is a problem with the following function: function themename_redirect_author_archive_to_profile
It seems that this might work
/* check if custom function file is active */
if( file_exists( WP_CONTENT_DIR . ‘/meso-custom-functions.php’ ) ) {
include_once( WP_CONTENT_DIR . ‘/meso-custom-functions.php’ );
}add_action( ‘template_redirect’, ‘authorblog_template_redirect’ );
function authorblog_template_redirect(){
if(is_author()){
if(get_query_var(‘author_name’)) :
$curauth = get_user_by(‘slug’, get_query_var(‘author_name’));
else :
$curauth = get_userdata(get_query_var(‘author’));
endif;
wp_redirect(‘http://www.your wesite name/members/’. $curauth->nickname );
}
}It helps a lot if you give some info about the ‘problem’.
In this case, I think he just forgot the
exit()
call.Try changing to:
wp_redirect( bp_core_get_user_domain( $user_id ) ); exit();
@shanebp Thank you so much. I’ll try that
- You must be logged in to reply to this topic.