I want to redirect subscribers to a special page after login to my WordPress Site ("http://www.my-cool-page.com/coolpeople") where "coolpeople" is a regular WordPress page. This is my code to redirect only the "subscribers":
$internStart = 'evenmorecoolpeople';
function loginRedirect( $redirect_to, $request_redirect_to, $user ) {
if ( is_a( $user, 'WP_User' ) && $user->has_cap( 'edit_posts' ) === false ) {
echo 'return URL: ' . home_url('/') . $internStart; die ();
return home_url();
}
return $redirect_to;
}
add_filter( 'login_redirect', 'loginRedirect', 10, 3 );
Now I want to replace "coolpeople" with a variable like:
$internStart = 'evenmorecoolpeople';
but ...
return home_url($internStart);
or ...
return home_url('/') . $internStart;
Does not work. Any Idea?
return home_url
, you put in the following code:echo 'return URL: ' . home_url('/') . $internStart; die ();
?loginRedirect
function where you're trying to use the $internStart variable.echo
line inside the brackets, beforereturn home_url
, but the redirect is still happening, then theif
conditions are not being met. The line I gave you should output the URL that is being used for the redirect, and then should not redirect.global $internStart;
at the begin of your function.