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');`

2 Answers 2


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


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();


$redirect_to = $_SERVER[HTTP_REFERER];
  • 1
    Everything will be lost when you upgrade your WordPress installation...
    – RRikesh
    Mar 15, 2013 at 6:06
  • just do it in the child theme. Aug 17, 2016 at 7:37
  • You should never edit WP core files.
    – Tom
    Apr 18, 2018 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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