Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

redirect_to how to make it simply work with get parameter or similar?

the issue was…

myappname_login_redirect needs to return $redirect_to in any case

otherwise the redirect to gets lost

background:

wp-login.php will render the redirect_to value into an input hidden into the login form.

so arriving at

wp-login.php?redirect_to=www.example.com

will render

an

<input type="hidden" value="www.example.com">

this value will be empty, if the filter does not return it by default

so fix…

   function myappname_login_redirect($redirect_to, $request, $user)
    {

      if ($user instanceof WP_User) {
        if (isset($user->roles) && is_array($user->roles)) {
          //check for admins
          if (in_array('administrator', $user->roles)) {
            // redirect them to the default place
            return $redirect_to;
          } else {
            //if something is set her for exceptions, we allow regular redirect as well
            if($_GET['myappname_allow_redirect']){
                return $redirect_to;
            }else{
//but normally we redirect to a standard url
                return 'somethingelse';
            }
          }
        } else {
          return $redirect_to;
        }
      }
      //is there a user to check?

return $redirect_to;
    }

    add_filter('login_redirect', 'myappname_login_redirect', 10, 3);

Related Posts:

  1. Change template dynamically
  2. Password field is empty when using wp_signon();
  3. How to redirect home page to another page after login for all user?
  4. How to Login a User inside a Plugin and Redirect to page?
  5. Redirection from a specific page for users logged in but not with membership
  6. Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
  7. framework for plugin/theme options panel? [closed]
  8. How to get the path to the current theme?
  9. ajaxurl not defined on front end
  10. What process do you use for WordPress development? [closed]
  11. Why does WordPress use outdated jQuery v1.12.4?
  12. What is the advantage of using wp_mail?
  13. Which hook should be used to add an action containing a redirect?
  14. Should Plugin Folders Include a Blank index.php File?
  15. How to include jQuery and JavaScript files correctly?
  16. Single functions.php or split into many small files?
  17. How can I configure Docker for developing and deploying a custom theme?
  18. Where to store PHP files created by plugin / themes
  19. Making a plugin file accessible via url rewrite?
  20. How to post data to same page in wordpress
  21. Can someone explain what wp_session_tokens are, and what are they used for?
  22. What is an alternative method to the WordPress private _doing_it_wrong() function
  23. Understanding WordPress functions’ naming conventions
  24. What is the difference between esc_html and wp_filter_nohtml_kses?
  25. Should I create a theme or a plugin?
  26. Include third party Javascript library which is not included in WordPress
  27. Init action hook running late after PayPal’s return url?
  28. Is there widely accepted phpDoc syntax for documenting which hook calls a function?
  29. Where do I start from
  30. WP 3.3 Tooltips API?
  31. jQuery in header or footer
  32. Check for featured image in WP_Query
  33. How to check WordPress website username and password is correct
  34. Password change when the user login first time
  35. redirect does not work in ajax function
  36. wp_remote_get doesn’t work with secure connections https?
  37. Log in from one wordpress website to another wordpress website
  38. Update exisiting site to 3.5 release candidate
  39. How do I Make a Theme “plugin-ready”?
  40. Custom admin_notices Messages Ignored During Redirects
  41. Using a Theme inside a Plugin directory
  42. Authoritative answer on which boots first – Plugins or Themes?
  43. How to Add Font Awesome Icons to WordPress Menus?
  44. Problems after wp_set_password() containing an apostrophe
  45. Authentication / login mechanism (non wp-admin)
  46. How to Add a .js file Only in one specific Page Dynamically to Head
  47. Show a user their recently viewed posts
  48. Escaping built-in WP function return strings
  49. How to Use WordPress Color Picker API in Custom Post Type Metabox
  50. Get file headers in custom file
  51. add_filter and remove_filter added before and after wp_query
  52. What is the difference between strip_tags and wp_filter_nohtml_kses?
  53. Custom theme sufficient or custom plugin neccessary for this feature set?
  54. Having Problem On Getting WP Post Gallery Images URL
  55. What’s the difference between hooks, filters and actions? [duplicate]
  56. How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
  57. Pages 404 in wordpress
  58. How to create custom home page via plugin?
  59. Add new user and add meta at once
  60. Can Not Redirect from Plugin-Registered Admin Page
  61. Front-End Form Submission in Shortcode
  62. Two-step login process – Is it possible?
  63. How to: get main plugin/theme file?
  64. How to debug WordPress correctly?
  65. Custom user profile, registration, login page with theme
  66. add_theme_support using a plugin
  67. wp-login.php — redirect logged in users to custom URL
  68. Redirect user after login/registration globally
  69. Featured Image not showing in admin
  70. How to Display Custom Post Type’s Gallery (images ) in Through WP_Query
  71. Customizer Not Saving Options
  72. Redirect to login page
  73. How to bundle a plugin with a theme, or vice versa
  74. What is better way to use Bootstrap inside admin panel?
  75. How do I approach removing menu items on the fly based on settings in my plugin?
  76. How to add Font Awesome 5 icons in WP Admin dashboard menu?
  77. How Can I setup WP CLI on Windows development machine running AMPPS?
  78. WP_LOCALIZE_SCRIPT doesn’t work
  79. What is the difference between these two methods of writing $ instead of jQuery in WordPress [closed]
  80. Whats the difference between blog_info(‘stylesheet_url’) difference get_stylesheet_uri()
  81. Error : “Updating failed: The response is not a valid JSON response” with custom shortcode
  82. What’s the better way to add an inline script?
  83. What function to hook for changes made in status and visibility of a post
  84. Example of uninstaller routine to remove all custom theme options from wp_options
  85. Metabox Not Showing on Custom Post Type But On Pages and Post
  86. Modify a Free Plugin available on wordpress.org & include with my Premium Theme? [closed]
  87. Paging on a future post loop?
  88. Cannot modify header information – headers already sent by pluggable.php
  89. Execution limit and Memory limit errors even i changed to 1024M and 600(cache.php,load.php)?
  90. Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?
  91. Backslashes being stripped from CSS
  92. How to redirect to action on custom page within admin section
  93. Best choice of options/settings framework for plugin/theme development
  94. What for the tables ending with the meta used in database of wordpress?
  95. Firing a function AFTER redirect
  96. How to determine if the current file is loaded in a plugin or in a theme?
  97. Is there any way to have Featured Text, as opposed to Featured Image?
  98. How to check if a stylesheet is already loaded?
  99. Find source of notice / warning / errors efficiently
  100. Problem with is_active_sidebar?
Categories plugin-development Tags login, plugin-development, redirect, theme-development, wp-redirect
Is it possible to have a Faceted Navigation/Filters on a Product Tag page?
Dropdown of existing posts in a metabox

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress