Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got a custom role for my site and users can only access their profile page, this appears to be the minimum for wordpress. However, the accounts are managed by us and this is a private site, we do not want users to be able to change their username, email or password using wordpress.

The only issue we have right now is logging in. The inner pages all require you to be logged in. We have a landing page with a link to the login page, for this link we apply redirect_to=/blog/ and after logging in you go to the blog. This works well enough for us.

However, if a user links to an inner page (or recieves the link in an email automatically, from subscription setting) then the link will require them to login, taking them to the login screen without the redirect_to parameter. This means they will go right to the profile page.

Why it goes to the profile page instead of the page they requested is beyond me, but we need to redirect them back to the blog.

Here is a function I set up with the intention that after logging in, you will get taken to the blog. At this point we don't care if a permalink doesn't work on first visit (of course they will once you log in).

But this function does not work. wp_signon is not triggered after a user logs in, but instead is used to log a user in.

What should I do?

function login_redirect() {
    wp_redirect( get_bloginfo( 'url' ) . '/blog/' );
}
add_action('wp_signon', 'login_redirect');`
share|improve this question

2 Answers 2

up vote 3 down vote accepted

There are two possible solutions for your problem.

  1. You can download "Login redirect" plugin from here: http://wordpress.org/extend/plugins/peters-login-redirect/

  2. You should use a login_redirect filter:

function my_login_redirect($redirect_to, $request) {
$redirect_url = get_bloginfo( 'url' ) . '/blog/';

return $redirect_url;
}
add_filter("login_redirect", "my_login_redirect", 10, 3);

More information about login_redirect filter: http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

share|improve this answer

Each of the solutions above seems to redirect the user to a specific pre-determined URL.

To redirect the user to the page that he was originally trying to access I think can only be achieved by (erk) editing wp-login.php and changing

$redirect_to = admin_url();

to

$redirect_to = $_SERVER[HTTP_REFERER];
share|improve this answer
1  
Everything will be lost when you upgrade your WordPress installation... –  RRikesh Mar 15 '13 at 6:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.