Title: Redirect Hook
Last modified: May 26, 2020

---

# Redirect Hook

 *  Resolved [Kurt Junker](https://wordpress.org/support/users/kjunker/)
 * (@kjunker)
 * [6 years ago](https://wordpress.org/support/topic/redirect-hook/)
 * Hi again,
 * sry to bother you again. I still have a challenge to redirect a user not to the
   default site (homepage) but to the path which was given with the uri.
 * I tried your hooks but they do what they have to do ( damn 😀 ).
    I think it 
   is a good idea to have also a hook which could be called before the redirect 
   from database is called.
 * So you have the possibility request the following url:
 * [https://mysite.com/calender/events/?rest_route=/jwt/v1/autologin&jwt=JWT](https://mysite.com/calender/events/?rest_route=/jwt/v1/autologin&jwt=JWT)
 * With the hook you can do something like this:
 *     ```
       add_action(
           'simple_jwt_login_redirect_hook',
           function(WP_User $user) {
               $requestUrl = $_SERVER['REQUEST_URI'];
               $redirectUrl = get_site_url() . strtok($requestUrl, '?');
               wp_redirect($redirectUrl);
           }
       );
       ```
   
 * Is it possible to add this option?!
 * Thanks a lot.
 * Kurt

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Nicu Micle](https://wordpress.org/support/users/nicu_m/)
 * (@nicu_m)
 * [6 years ago](https://wordpress.org/support/topic/redirect-hook/#post-12892034)
 * Hello Kurt,
 * Yes, it is possible. I will add this hook just before the redirect.
 * I will release this in a couple of hours and I will come back with an example
   on how you can use it.
 *  Plugin Author [Nicu Micle](https://wordpress.org/support/users/nicu_m/)
 * (@nicu_m)
 * [6 years ago](https://wordpress.org/support/topic/redirect-hook/#post-12894190)
 * Hello,
 * Please update the plugin to version 1.6.3 and you will find the hook `simple_jwt_login_redirect_hook`.
 * This hook is called before the user is redirected to the page he specified in
   the login section.
 * Example of usage:
 *     ```
       add_action(
           'simple_jwt_login_redirect_hook',
           function($url) {
               $redirectUrl = $url . '?something=123'
               wp_redirect($redirectUrl);
           }
       );
       ```
   
 * PS: $url is the URL where the user is redirected after auto-login.
 * Best regards.
    -  This reply was modified 6 years ago by [Nicu Micle](https://wordpress.org/support/users/nicu_m/).
 *  Thread Starter [Kurt Junker](https://wordpress.org/support/users/kjunker/)
 * (@kjunker)
 * [6 years ago](https://wordpress.org/support/topic/redirect-hook/#post-12895310)
 * Hi,
 * it works!
 * Thanks a lot for your fast support.
 * Best Regards.
 *  Plugin Author [Nicu Micle](https://wordpress.org/support/users/nicu_m/)
 * (@nicu_m)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/redirect-hook/#post-13042817)
 * Hello Kurt,
 * Thank you for donating to this plugin.
 * Have a nice weekend.
 * Best regards,
    Nicu.
 *  [igurman](https://wordpress.org/support/users/igurman/)
 * (@igurman)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/redirect-hook/#post-13429280)
 * Hi [@nicu_m](https://wordpress.org/support/users/nicu_m/) , was this tested with
   the latest WP version? My plugin login setting is set to redirect to homepage,
   enabling the hook & calling this on functions.php:
 *     ```
       add_action(
           'simple_jwt_login_redirect_hook',
           function($url) {
               $redirectUrl = $url . '/page';
               wp_redirect($redirectUrl);
           }
       );
       ```
   
 * $url therefore should be the homepage, so I should get to homedomain.com/page
   right? It Seems to just redirect to regular homepage, whatever I put at the $
   redirectUrl, wether it’s ‘/page’, ‘page’, ‘?something=123’, etc, still just plain
   homepage. Any idea why?
 * Ilya
 *  Plugin Author [Nicu Micle](https://wordpress.org/support/users/nicu_m/)
 * (@nicu_m)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/redirect-hook/#post-13429309)
 * Hello [@igurman](https://wordpress.org/support/users/igurman/),
 * Yes. It is tested with the latest WordPress version.
 * Please make sure you have enabled the hook from Plugins Settings-> Hooks and 
   save the settings.
 * In the code, I make a verification if the hook is enabled, and only then the 
   action is triggered.
 * Also, this function has 2 arguments. Here is a sample how you should call it:
 *     ```
       add_action(
           'simple_jwt_login_redirect_hook',
           function($ur, $requestl) {
               $redirectUrl = $url . '?something=123';
               wp_redirect($redirectUrl);
           }
           ,10
           ,2
       );
       ```
   
 * Best regards,
    Nicu.
 *  [igurman](https://wordpress.org/support/users/igurman/)
 * (@igurman)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/redirect-hook/#post-13429321)
 * Hi [@nicu_m](https://wordpress.org/support/users/nicu_m/) Nicue thanks for the
   quick reply. Yes that’s how I’m using it and the hook is enabled. Could it be
   something to do with the install being a multisite? (Even though this is attempted
   for a single subsite)
 *  Plugin Author [Nicu Micle](https://wordpress.org/support/users/nicu_m/)
 * (@nicu_m)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/redirect-hook/#post-13429348)
 * I’ve just checked this o the latest WordPress version, in a site from my multisite
   network.
 * Try to add this code in `wp_config.php` or at the bottom of `routes.php` (wp-
   content/plugins/simple-jwt-login/routes.php’).
 * My guess is that the file where you wrote the code, it is not included.
 * Let me know if this works for you.
 * Best regards,
    Nicu.
 *  [igurman](https://wordpress.org/support/users/igurman/)
 * (@igurman)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/redirect-hook/#post-13435059)
 * [@nicu_m](https://wordpress.org/support/users/nicu_m/) appreciate your reply 
   but doesn’t seem to matter where I add it, the hook isn’t called.
    I even created
   my own plugin, and activated on that subsite: [https://ibb.co/gjQnrQR](https://ibb.co/gjQnrQR)
 * The hook is enabled:
    [https://ibb.co/C2mtK5f](https://ibb.co/C2mtK5f)
 * It just redirects to whatever is mentioned on the ‘login’ tab of the plugin (
   homepage, dashboard..) and ignores the hook.
 * Not sure what I’m doing wrong and sorry for the constant bothering here.
 * Ilya
    -  This reply was modified 5 years, 8 months ago by [igurman](https://wordpress.org/support/users/igurman/).

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Redirect Hook’ is closed to new replies.

 * ![](https://ps.w.org/simple-jwt-login/assets/icon-256x256.png?rev=2106097)
 * [Simple JWT Login – Allows you to use JWT on REST endpoints.](https://wordpress.org/plugins/simple-jwt-login/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/simple-jwt-login/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/simple-jwt-login/)
 * [Active Topics](https://wordpress.org/support/plugin/simple-jwt-login/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/simple-jwt-login/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/simple-jwt-login/reviews/)

 * 9 replies
 * 3 participants
 * Last reply from: [igurman](https://wordpress.org/support/users/igurman/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/redirect-hook/#post-13435059)
 * Status: resolved