Redirect Author Archive Page to BuddyPress User Profile
If you have enabled BuddyPress and want to redirect to user's profile when someone tries to access the author archive page, you can use the following code.
1 2 3 4 5 6 7 8 9 | function buddydev_author_redirect_to_profile() { if ( is_author() && function_exists( 'bp_core_redirect' ) ) { $author_id = get_queried_object_id(); bp_core_redirect( bp_core_get_user_domain( $author_id ) ); } } add_action( 'template_redirect', 'buddydev_author_redirect_to_profile' ); |
Isn't that a sweet little hack 🙂
which file should be edited?
Hi Yaser,
You can put it in your theme's functions.php or in wp-content/plugins/bp-custom.php
I'm wondering why the use of "function_exists( 'bp_core_redirect' )" if it's not being used and you are redirecting on "template_redirect".
Any reason? o.O
Hi Renato,
Please see the condition inside the if block.
1. the bp_core_redirect is being used.
2. I am using that for 2 purposes.
a) It is a BuddyPress function, so It guarantees that BuddyPress is enabled and
b) I don't have to call exit after wp_redirect.
Hope that clarifies.