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

Require re-login when logged-in user attempts to access restricted page

When you say that the user is “logged in but with the wrong credentials” I have to assume you mean “the user is logged in with correct credentials but does not have the permissions needed to access the page”. If users were able to log in with the wrong credentials you site would be badly broken.

That redirect, all by itself, won’t cause the error you describe. You can prove that by pasting the following into your theme’s header.php:

wp_redirect(wp_login_url( get_permalink() ));
exit;

Any attempt to get to a front end page will redirect but there is no infinite redirect loop. The problem must be where you have placed that code and you don’t include that information. I expect you have it somewhere– a hook maybe– that loads for the login page as well so that when the redirect gets started it never stops (until the browser gives up). Sorting that out will probably solve the issue at hand.

I have to wonder why you are using a user meta field instead of a capability, though. I don’t see why the built in permissions system can’t handle this.

Related Posts:

  1. Action wp_login_failed not working if only one field is filled out
  2. Restrict PDF links
  3. Restricting frontend acess based on user role otherwise redirect to login form
  4. wp_get_referer not working properly after wp_redirect
  5. Login redirects and query strings
  6. How can I login as admin after redirect to custom login page
  7. Redirect wp-login
  8. Do more action after login successfully
  9. How to restrict access to a single for users I’ve authorized? [closed]
  10. Requiring login for specific pages
  11. Hide Author page from others
  12. force login loophole
  13. This webpage has a redirect loop issue
  14. WordPress site login Redirect
  15. URL Restrictions? Need only people who are logged in AND have a specific role (or roles) to access all pages for a site
  16. Problem in auto login after registration
  17. WordPress Redirect After logging
  18. redirect_to not Including Hashtag from URL
  19. A way to redirect users when they log in based on their current page
  20. Login form- no feedback
  21. In Django, how do I know the currently logged-in user?
  22. Can I programmatically login a user without a password?
  23. Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
  24. Is there any way to rename or hide wp-login.php?
  25. How to login with email only no username?
  26. How can I redirect user after entering wrong password?
  27. Increase of failed login attempts, brute force attacks? [closed]
  28. Login page ERROR: Cookies are blocked due to unexpected output
  29. Separate registration and login for different roles
  30. SSO / authentication integration with external ‘directory service’
  31. Preventing session timeout
  32. How reduce wordpress login session timeout time?
  33. How to prefill WordPress registration with social details
  34. Check for correct username on custom login form
  35. Disallow user from editing their own profile information
  36. I can’t access my site via wp-admin
  37. ‘Password field is empty’ error when using autofill in Chrome
  38. Removing username from the ‘wordpress_logged_in’ cookie
  39. How to show ‘login error’ and ‘lost password’ on my template page?
  40. What is $interim_login?
  41. Custom login form
  42. How to prefill the username/password fields on the login page
  43. wp_signon returns user, but the user is not logged in
  44. Adding extra authentication field in login page
  45. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  46. Redirect user using the ‘wp_login_failed’ action hook if the error is ’empty_username’ or ’empty_password’
  47. wp_signon() does not authenticate user guidance needed
  48. What exactly is ReAuth?
  49. What are the differences between wp_users and wp_usermeta tables?
  50. Login members using web services
  51. Make my wordpress blog remember my login “forever”
  52. How to check in timber if user is loggedin?
  53. How do I change the language of only the login page?
  54. Disable WordPress 3.6 idle logout / login modal window / session expiration
  55. Stop WordPress from logging me out (need to keep me logged in)
  56. Woocommerce registration page [closed]
  57. How to disable autocomplete on the wp-login.php page
  58. Share login data/cookies between multiple installations
  59. Synchronize WordPress user accounts across multiple domains and installations without using WordPress MU
  60. How to pass users back and forth using session data?
  61. How do I change the logo on the login page?
  62. Why does WordPress hide the reset password key from the URL?
  63. Is it possible to sign in with user_email in WordPress?
  64. How to use current_user_can()?
  65. Avoid to load default WP styles in login screen
  66. WordPress registration message
  67. How to fake a WordPress login?
  68. how to display the wordpress login and register forms on a page?
  69. Does wp_logout_url() destroy a session? (Logging out question)
  70. How can I send a welcome email to a user AFTER they login for the first time?
  71. Can not login with correct username and password
  72. Website Visible only to Registered users
  73. How can i increase the login expiration length?
  74. How do I use add_action from a class method?
  75. How to remove the WordPress logo from login and register page?
  76. How can I add a custom script to footer of login page?
  77. Brute force attack?
  78. Customize wp_new_user_notification_email()
  79. Need to execute a cron job
  80. Password change when the user login first time
  81. Login email after registration never sent or received
  82. How can I create a separate blog that is private?
  83. How to keep always logged in development environment
  84. Add Confirm Password field in wp-login.php Password Reset page
  85. Integrate recaptcha and wp_signon – what is needed?
  86. Stop users from logging in from multiple locations
  87. I want to disable E-Mail verifcation / activation when a user signs up for my WordPress site
  88. custom login page redirect to logged in user profile page
  89. Email address or username used to login in wordpress
  90. How do I check if a post is private?
  91. Front-end login: Redirect user to the post they had created
  92. Receiving “This content cannot be displayed in a frame” error on login page
  93. My login form does not work
  94. Programmatically log in a wordpress user
  95. Getting “Cookies are blocked or not supported by your browser” on login page
  96. What is the purpose of logging out after WordPress upgrade?
  97. Is it alright for two people to simultaneously be logged into a WP site as administrator?
  98. wp-login.php redirecting to HTTPS
  99. Display last login time
  100. How to customise wp-login.php only for users who are setting a password for the first time?
Categories login Tags content-restriction, login, wp-redirect
Custom RSS feed – blank page
Change Post Meta via AJAX from the posts list table

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