how to redirect in WP, BP to a custom page
I'm trying to redirect users to a custom page I made when they log in, but I'm not sure I have it right. I don't know exactly which function or variables to use. I want to use the index.php as a way to redirect users. I'm working in wordpress latest, as well as buddypr开发者_运维问答ess latest.
So ok, this is what I have:
function my_redirect() {
global $bp;
if ( $bp->current_component == $bp->root_domain ) {
bp_core_redirect($bp->root_component == MY_CUSTOM_SLUG );
}
}
The slug I created is in the root, so it looks like this:
www.mysite.com/mypage
Any ideas?
This can be achieved using redirect_to
in your login links. This will require editing of your template.
$redirect_url = "www.mysite.com/mypage"
// if $redirect_url exists, it will add it, otherwise print the regular login link
<a href="<?php bloginfo('url'); ?>/wp-login.php<?php
if($redirect_url) {echo "?redirect_to=".urlencode($redirect_url)."\"";}?> >
log in
</a>
This will probably make you want to cut your face off at some point, since you will have to edit the template every time you want to change your redirect page.
I am not sure exactly what you need this for so here are two ways to do it.
1) You can set any page in wordpress to be the default home page. In the dashboard go to Settings>Reading and under the setting "Front page displays" you can choose "A static page (select below)"
2) You can use the php header location function used:
header( 'Location: http://www.yoursite.com/new_page.html' ) ;
You would place it before your content and it works well with whatever conditions you like.
For more information - http://php.net/manual/en/function.header.php
You may try the Login Redirect plugin. You can choose where to redirect the user after login. It is role based.
精彩评论