Redirect WordPress Author Archive to BuddyPress Profile
Need to redirect from users's WordPress post archive page to their BuddyPress profile? It's easy.
You can put the following code into bp-custom.php or in your theme's functions.php
1 2 3 4 5 6 7 8 9 10 11 12 | /** * Redirect Author archive to user profile. */ function buddydev_redirect_author_archive_to_bp_profile() { if ( is_author() ) { $redirect_url = bp_core_get_user_domain( get_queried_object_id() ); // Update it if you want to move to sub tab. bp_core_redirect( $redirect_url ); } } add_action( 'bp_template_redirect', 'buddydev_redirect_author_archive_to_bp_profile' ); |
You can even redirect to specific user profile tab(component). For example, we can redirect to the view profile page by changing $redirect_url to
1 | $redirect_url = bp_core_get_user_domain( get_queried_object_id() ) . bp_get_profile_slug(); |
or you can even hard code to specific url like
1 | $redirect_url = bp_core_get_user_domain( get_queried_object_id() ) . '/groups/'; |
I will suggest to avoid hard coding the tab slug as they can be changed by different constants.
Feel free to extend and have fun!