Hi @tatakatte
Try this:
function my_login_redirect() {
if ( is_user_logged_in() && bp_is_register_page() )
bp_core_redirect( home_url() . '/stream/' );
}
add_action( 'template_redirect', 'my_login_redirect' );
Hi @henrywright
I tried this little code but my site gave me this error
Warning: Cannot modify header information - headers already sent by (output started at /home/emncrz/public_html/wp-content/plugins/bp-custom.php:9) in /home/emncrz/public_html/wp-includes/pluggable.php on line 1178
I’m not really sure how this pluggable.php works. Sorry for being such a noob.
Where did you paste the code? It should go in your theme’s functions.php file.
@tatakatte
Did you put Henry’s code in with opening and closing php tags? Make sure there is no white space between the opening and closing php tags as this will give an headers already sent error.
@tatakatte
Should work fine in the themes functions.php as @henrywright specified or in bp-custom.php
It didn’t work. I tried placing the code both in functions.php and bp-custom.php 🙁
Were there any error messages? Can you describe what is happening when you add the code to functions.php?
Nothing happened. It’s still redirecting to /members/. I’m not really sure how I should put the opening and closing tags that @bphelp mentioned, but I just used /** and */ before and after the code you gave me.
@tatakatte
Maybe your slug is wrong in the URL. Try this:
function my_login_redirect() {
if ( is_user_logged_in() && bp_is_register_page() )
bp_core_redirect( home_url() . '/activity/' );
}
add_action( 'template_redirect', 'my_login_redirect' );
Reason being you may have changed the pages name but if you didn’t change the slug as well it wouldn’t work.
You don’t need the /**
and */
@Here’s everything that I have in my functions.php
<?php
/**
* @package WordPress
* @subpackage
* @author
* @since 1.0
*/
/**
* Child Theme Functions
* Add custom code below
*/
function my_login_redirect() {
if ( is_user_logged_in() && bp_is_register_page() )
bp_core_redirect( home_url() . '/stream/' );
}
add_action( 'template_redirect', 'my_login_redirect' );
As for @bphelp’s, the slug is really /stream/. I checked it after reading your reply, but it really is /stream/. Also shouldn’t it return a 404-error if it’s a non-existent page? Please correct me if my understanding is wrong.
And you’re definitely logged in and visiting your register page?
Try changing the last line to:
add_action( 'template_redirect', 'my_login_redirect', 1 );
@tatakatte
Did you make sure you set your registration page as a static page in dashboard/settings/reading because I just tested it and it works as expected. On my dev environment when I go to the site without being logged in it redirects me to the registration page. Once I log in it redirects to the activity stream. Isn’t that what you wanted?
@henrywright
I didn’t use any priority and it worked so I don’t think that is the issue. Your code worked fine when I tested it as is.
@henrywright
This one worked well. Now, it’s redirecting to /stream/!
function my_login_redirect() {
if ( is_user_logged_in() && bp_is_register_page() )
bp_core_redirect( home_url() . '/stream/' );
}
add_action( 'template_redirect', 'my_login_redirect', 1 );
@bphelp I’m not really sure why it required priority to work, maybe due to a plugin that I’m using?
@bphelp thanks for testing 🙂
@tatakatte yeah, it’s likely something in your installation is already redirecting. The priority just makes sure my_login_redirect()
is executed first.
I see… I have Theme My Login plugin installed. Maybe it could be causing the problem? Thanks for your help @bphelp and @henrywright! 😀