Redirect Post or Comment author link to AnsPress profile

5.49K viewsCore
0

Hi all!
Up until now, I was using BuddyPress and I was redirecting posts or comments author link to their BP profile (if they were registered). I was using this snippet :

// Redirect Author to BP Profiles
add_action( 'template_redirect', 'redirect_author_archive_to_profile' );
function redirect_author_archive_to_profile() {
if(is_author()){
$user_id = get_query_var( 'author' );
wp_redirect( bp_core_get_user_domain( $user_id ) );
}
}

I didn’t write this on my own but I believe it could be modified to do the same thing and redirect to AnsPress profiles for Registered Users. I’m guessing it’s mainly the last line that should be modified with a reference to the logged in user id. Something about that:

ap_user_link( $userid )

Anybody has any idea of the right syntax to use?

Thanks in advance!
Fred 😀

0

Here you go:

// Redirect to AnsPress profiles
add_action( 'template_redirect', 'redirect_author_archive_to_profile' );
function redirect_author_archive_to_profile() {
	if(is_author()){
		$user_id = get_query_var( 'author' );
		wp_redirect( ap_user_link( $user_id ) );
	}
}
Posted new comment

Thanks for the support quick answer. 😉 It makes sens but it’s not working. Gonna investigate it a bit more. It helps me understand php little by little. 😉

I have dazzling colorib theme. So where I have to add this code so that I can change the meta-box author url link? Thank you

You are viewing 1 out of 2 answers, click here to view all answers.