We have a link on our site which will redirect users to the edit profile page when they are logged in.

We have same link for the anonymous users which will redirect the user to login page when it clicked.

We would like to redirect users to the edit profile page after login but if users use normal login link, after login, they are redirected to the homepage.

I would like to know how we can redirect users to edit profile page after login only if they clicked on the edit profile link.


2 Answers 2


In Edit Profile link append destination parameter like:

  $editlink = l(t('Edit Profile'), 'user/login', array('query' => array('destination' => 'user/UID/edit')));

Then after login, it will redirect to profile edit page.

  • When I use this as Edit Profile link, it will redirect users to a blank page ! it should redirect to login page : example.com/user !
    – Sinf
    Nov 17, 2016 at 9:15
  • Try changing url values, above one is working for me in one of my project. add user_is_anonymous condition
    – Ajay Reddy
    Nov 17, 2016 at 9:56
  • Thx, now I have another problem ! how can I get UID after user login ? if not, it will not redirect to user edit profile ! it just show access denied ! I need something like : user/xxx/edit which xxx is the logged user UID.
    – Sinf
    Nov 17, 2016 at 11:30
  • Do one thing, change destination to your custom URL like "user-edit" and in user-edit call back redirect to "user/UID/edit" . TO get UID, global $user; $uid = $user->uid; For access denied "give permissions" to user, to edit their own profile.
    – Ajay Reddy
    Nov 17, 2016 at 11:33

There are different ways to do this, refer this https://www.drupal.org/node/683696

  • Please read my question again ! there is some conditions ! I already saw that of course before asking this question !
    – Sinf
    Nov 17, 2016 at 9:05
  • are you trying to do this with a custom module?
    – ana
    Nov 17, 2016 at 9:59

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.