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

How do i make my wordpress website private?

You can simply check if the user has an specific role, and redirect them to homepage if they try to access the admin panel.

function redirect_to_front(){
    // Check if we are on the admin panel, and the user is not an admin
    if( is_admin() && !current_user_can( 'administrator' ) ){
        // Redirect them back to front
        wp_safe_redirect( site_url() );
        exit();
    }
}
add_action('init', 'redirect_to_front');

This is just an example. You should alter the code, and change the capabilities to fit your purpose. The current_user_can() function accepts both capability and roles.

Related Posts:

  1. How to keep track of user logins?
  2. My custom page template with is_user_logged_in() does not detect that I’m logged in
  3. Replacing the WordPress password validation
  4. WordPress auto login after registration not working
  5. Allow up to 5 Concurrent Login Sessions
  6. Why does is_user_logged_in() return false after redirect from another site?
  7. Pre-populate Username Field
  8. Get user info outside WordPress
  9. How can I secure a WordPress blog using OpenID from a single provider?
  10. Is it possible to get a user with just the password field?
  11. Redirect after login based on user role (custom login page)
  12. Check for user meta data at Login
  13. Redirect User to Homepage if no other redirect is specified
  14. Use phpbb user database for WordPress
  15. WordPress to use Drupal users’ credentials
  16. Best way to have an per-user customized private section
  17. Share user table from WP with Drupal
  18. How can I allow password reset based on logins containing the @ character?
  19. A way to count logged in users and display count?
  20. stop login if user_status equal zero
  21. Redirect user to login before viewing custom post
  22. Change the user_login at registration
  23. Max no of simultaneous active sessions for a single user
  24. When I try to login in wordpress it is showing “USER Doesn’t Exists”
  25. Should I encrypt the response that triggers an Ajax action? Is nonce sufficient?
  26. Redirect subscribers to last viewed page after log-in
  27. wordpress disable login for unverified user
  28. Reset Password policy
  29. Rewrite Rules and Login Issue
  30. Is possible to allow user to login with different role?
  31. Use WordPress Login for a non-wordpress site
  32. WordPress Login Customization for External Authentication
  33. Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
  34. Is there any action /filter hook I can use to disable login for some user role?
  35. How to check User Role and redirect to specific page according to Role when login in WordPress?
  36. Display video on homepage for users who have not logged in
  37. How do you manage your pages or functions that require logged-in users?
  38. How can i login with user’s password in WordPress being an admin?
  39. Delete a user from frontend
  40. Check if user is logged in via JS? [duplicate]
  41. Use members from 1 site on another one
  42. Can I edit the database to change a login?
  43. how redirect users to custom login page when “login to reply” is clicked? [duplicate]
  44. User(s) already exists show error please provide a valid username
  45. wp_generate_password sets password but can’t login using created password
  46. add class to element if user is not logged in [closed]
  47. Is there a way to call via javascript if a user is logged-in on a static html file?
  48. Restricting wordpress login sessions for a web app
  49. How to connect wordpress user with my own APP user?
  50. How to change default username field after login
  51. The same session information for peer users on two different WordPress servers
  52. WP users cant reset password
  53. Check for empty username or password on login
  54. $user_login is not working if author has only 1 post
  55. Specific Content on pages based on user
  56. user and usermeta table not found
  57. custom login form, guide me
  58. Front end login and page restriction
  59. Changing user_login ends current session
  60. Current User Seeing Another Logged In User Info
  61. Privacy in WordPress
  62. Redirect based on log-in status per JavaScript
  63. Securely log in a user without a password using a link?
  64. Integrating Facebook Registration (and Login) on a WordPress page
  65. WordPress – Security Question at Login from User’s Meta Data
  66. determine active user browser at the same time
  67. How to track all users logged into a site?
  68. Cant edit profile from frontend
  69. How to authenticate/verify login credentials & check for user meta without logging in?
  70. Will users still be able to log in if I change host?
  71. redirect to my login page if not logged in
  72. If the current user is an administrator or editor
  73. Editor can create any new user except administrator
  74. How do I add a field on the Users profile? For example, country, age etc
  75. How do I display logged-in username IF logged-in?
  76. How to allow an user role to create a new user under a role which lower than his level only?
  77. user_login vs. user_nicename
  78. How to programatically change username (user_login)?
  79. Change the Author Slug from Username to Nickname
  80. Remove Ability for Other Users to View Administrator in User List?
  81. Difference between update_user_meta and update_user_option
  82. Make display name unique
  83. Make WooCommerce pages accessible for logged in users only
  84. Find out if logged in user is not subscriber
  85. WordPress usermeta scaling for thousands of users
  86. How to get WordPress Username in Array format
  87. Display user registration date
  88. Is there a is_user_logged_in() for multisite?
  89. Get multiple roles with get_users
  90. get_user_meta() doesn’t include user email?
  91. Confirmation required on email change
  92. How to Merge Two Authors Into One?
  93. Whats the best way to share user data across multiple WordPress websites?
  94. get_current_user_id() returns 0?
  95. How do I require authorization / login to view a specific set of posts / pages?
  96. How to get userid at wp_logout action hook?
  97. Groups of capabilities: users with multiple roles?
  98. Is there a way to merge two users?
  99. User-edit role setting distinct from wp_capabilities? [closed]
  100. List users by last name in WP_User_Query
Categories users Tags login, private, users
Is there any way to allow users to access content before it’s published?
WordPress loads Jquery Automatically – is my idea correct to add it to the footer?

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