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

Trim the repeated value in URL

Parse Url, check params, and build it again:

$url = "http://localhost/sarkari/wp-login.php?action=logout&redirect_to=%2Fsarkari%2F&_wpnonce=b5e3b954df&redirect_to=http://localhost/sarkari/2017/06/01/new-sample-post/";

function trimUrlParams($url, array $params) 
{
 $parts = parse_url($url);
 parse_str($parts['query'], $query);
 $newQuery = array();

 if (is_array($query) && sizeof($query) > 0 ) {
  foreach ($query as $variable=>$value) {
   if (in_array($variable, $params)) {
    $newQuery[$variable] = $value;
   }
  }
 }

 return $parts['scheme']."://".$parts['host'].$parts['path']."?". http_build_query($newQuery);
}


$newUrl = trimUrlParams($url, array('action', 'redirect_to', '_wpnonce'));

Related Posts:

  1. Change register form action url
  2. How To Change Wp Register/Login URL Permanently To My Custom Page
  3. Changed Wordress Address URL Accidently
  4. redirect_to not Including Hashtag from URL
  5. Remember me doesn’t work with www?
  6. Can’t access wordpress mgt dashboard until propogation finished?
  7. Is there any way to rename or hide wp-login.php?
  8. Preventing session timeout
  9. I can’t access my site via wp-admin
  10. how to display the wordpress login and register forms on a page?
  11. Website Visible only to Registered users
  12. How do I use add_action from a class method?
  13. I want to disable E-Mail verifcation / activation when a user signs up for my WordPress site
  14. How do I check if a post is private?
  15. Is it possible to use a forgot password url filter?
  16. Action wp_login_failed not working if only one field is filled out
  17. Display last login time
  18. Intentionally Force Failed Login WordPress
  19. How do I turn off the ability to login?
  20. What hooks should I use for pre-login and pre-registration actions?
  21. WordPress Login Footer URL
  22. Save last login date in global before change it?
  23. how to update current logged user username
  24. Custom Reset Password & Forgot Password Front End Forms
  25. Admin user getting message ‘You need a higher level of permission’
  26. How to implement Google reCaptcha without installing a plugin?
  27. Problem with logging in WP users automatically
  28. advance membership managment
  29. Logins through alias
  30. Is back-end access not required for an app to post to my blog?
  31. Remove WordPress Login Animation
  32. Redirect users to a front end wp login page
  33. Redirecting or displaying a message on first login
  34. Deny a user role to log in after register
  35. wp_get_referer not working properly after wp_redirect
  36. Login Button CSS
  37. Force Users to Login – loop problem
  38. Is there a better way than checking user is logged in to show or hide adminbar?
  39. How to redirect after login getting a variable from url (for example with the language)
  40. How do I replace “Username” in the WordPress login form?
  41. How can I do a URL redirection when an user uses wrong login details?
  42. Show errors on custom login form [duplicate]
  43. Change login_message using title
  44. Changing WP login credential [closed]
  45. Login with serialized password
  46. Index page and random posts needs a forced refresh in order to show new content
  47. How to change wordpress Log In text
  48. Single sign on with custom site
  49. By registering always make uppercase the first letter of the login
  50. Best option to implement external register/login to WP from self-made API
  51. Enqueue new login style sheet
  52. WordPress Conditional Login Links
  53. Secure login on wordpress [closed]
  54. Do more action after login successfully
  55. How can I password protect a WordPress site without requiring users to log in?
  56. Can’t login to my own website
  57. I cannot login and am getting this error message. .
  58. Can I Get User ID at Login?
  59. Cannot log into migrated site
  60. WordPress SSL not working [closed]
  61. I want login using email not username wordpress front end
  62. How to Remove default “Login” link
  63. How to unpublish my new site while working on it?
  64. How to force “remember me” users to login again?
  65. Reset Password Limit not working
  66. User not able to sign in after wp_authenticate() and wp_signon() wordpress
  67. WordPress site login Redirect
  68. Thank You Page Layout Differs on User Logged In Status
  69. On Homepage “is_user_logged_in()” function is not working after login and it is working after refresh the page?
  70. Problem in auto login after registration
  71. Cant reset password my wordpress password not even with phpMyAdmin
  72. Get WordPress logged in username from root domain when WP is installed in a subfolder
  73. How to invalidate `password reset key` after being used
  74. wp-cron event doesn’t run when custom login API is enabled
  75. Does it make sense to check a nonce on user log in?
  76. Special link for no automatic login (no username and no password)
  77. Global login to password protected pages
  78. Disable / Remove Password for Login WordPress
  79. WordPress Auto Login From Email Link
  80. Building a custom login form – encountering issues
  81. Making sure two different wordpress website has auto login
  82. Site login failed due to strange warning
  83. How do i Redirect specific user(WooCommerce Sign-in not wordpress admin page sign-in) to specific page
  84. Chosen user password in registration is not being accepted on Login
  85. Improvements to “limit login attempts” plugin
  86. Add a required field to Registration
  87. loging to Admin page not working at all
  88. Can’t login through wp-login.php on fresh installation
  89. WordPress Cookies – wp_set_auth_cookie
  90. Authenticate return value
  91. Front-end login problem: requires re-authorization when accessing dashboard
  92. Using wp_login_form passowrd as undefined
  93. Redirect non-members to about/intro page
  94. When trying to login if already logged in, form just shakes – error message remains empty
  95. Handle POST request sent from an external site for login?
  96. Can not login after moving to cloudflare and adding rules
  97. Inconsistent login state
  98. Can i hide a dynamically created div to logged out users?
  99. Why am I not able to login to the admin
  100. WP behind haproxy weirdness
Categories login Tags login, urls
How to change WP’s post editor’s font
Manual Woocommerce Complete order Emails

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