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

Check if user is logged in else login page

if(!current_user_can('administrator')) {
    wp_redirect( wp_login_url() );
}

This will redirect non-admins to login URL. Of course, logged in non-admins will be a bit confused. You’ll want to run this before get_header()

Related Posts:

  1. The website cannot display the page
  2. Admin login not working
  3. Send admin to a different login than users?
  4. Redirect non-admin after login, and in url – /admin
  5. How to change the title attribute for the WP logo image on wp-login.php
  6. WordPress login process is hanging
  7. You do not have permission to access this document on form submit
  8. Different customer login form than administrator login form?
  9. What are the standard admin CSS id/class tags?
  10. Admin Ajax is returning 0
  11. Add custom column to Users admin panel
  12. wp_verify_nonce vs check_admin_referer
  13. Add a Separator to the Admin Menu?
  14. How to determine whether we are in add New page/post/CPT or in edit page/post/CPT in wordpress admin?
  15. how to know if admin is in edit page or post [duplicate]
  16. Modal window from within WordPress admin
  17. Where in WP can I check history or log of updates of plugins etc?
  18. Adding a custom admin page
  19. How does admin-ajax.php work?
  20. How to remove entire admin menu?
  21. How do I remove dashboard access from specific user roles?
  22. How can I speed up my WP admin section?
  23. How to pass parameters to admin_notices?
  24. Admin: very slow edit page caused by core meta query
  25. if admin is logged in
  26. Search posts by ID in admin
  27. How to Change the Default Home Page for the WordPress Dashboard?
  28. Setting admin edit panels & metaboxes positions and visibility for ALL users and admins
  29. Find out which moderator approved comment?
  30. How To Remove WordPress Version From The Admin Footer
  31. Sort pages in loop by admin’s page attributes order field?
  32. Edit “thank you for creating with WordPress” in version 3.3.1
  33. Hide other users’ posts in admin panel
  34. Set Default Admin Colour For All Users
  35. Editor Styles and Typekit
  36. WordPress admin stylesheet
  37. This CSS Stuffing Works, But Is This A Good Practice?
  38. Is it possible to create a WordPress tour? V3.3.1
  39. Securing Admin Accounts – Username Discovery
  40. is_admin() returns true when using admin-ajax.php from front end script
  41. How to save dismissable notice state in WP 4.2?
  42. How do I optimize a custom post type admin page with 25,000 posts?
  43. Settings API – adding setting fields dynamically?
  44. Disable Media Uploads to non Admin Users
  45. How do I load a CSS style into WordPress admin area only?
  46. Allowing admin-ajax.php to receive “application/json” instead of “x-www-form-urlencoded”
  47. Can an admin check passwords of registered users?
  48. How can I target WordPress 3.8 new interface MP6 with CSS?
  49. Notification that the admin is online
  50. Does wordpress create activity, update logs?
  51. sort child pages on admin
  52. How-to make the admin area mobile friendly [closed]
  53. How to remove list view from media library?
  54. How to disable the “Your site has updated to WordPress x.y.z” admin email?
  55. Load plugin scripts and styles only on plugin page
  56. Plugin to remove Admin menu items based on user role?
  57. How to obtain the user ID of the current profile being edited in WP-Admin?
  58. 3.3: How do you hide the new dashboard welcome panel?
  59. Add my own button next to “Screen options” and “Help” in the admin
  60. WP List Table custom quick edit box – post meta data missing and columns change on submit
  61. Settings API – easiest way of validating checkboxes?
  62. Are there any action like ‘init_frontend’
  63. Should I use is_admin() inside ‘admin_init’ hook callback
  64. Custom admin email for new user registration
  65. Send Admin Emails to Multiple Email Addresses
  66. How do I set up the defualt page icon for admin menu?
  67. Prevent author from changing their posts if admin has modified
  68. Cannot access admin panel
  69. Make A WordPress Page Accessible To Admins Only, Redirect Other User Roles
  70. Disable all https in WordPress
  71. localhost/wp-admin on my local redirects to production site’s /wp-admin
  72. How to remove administrator role in settings -> general -> New User Default Role?
  73. Is there a more efficient admin search function/plugin?
  74. Can a users profile be put under the dashboard menu
  75. WordPress Admins or Roles per Page
  76. Styling Shortcodes in Visual Editor
  77. initial sort order for a sortable custom column in admin
  78. Showing WP_Error message with admin_notice action hook
  79. WordPress admin screen very slow / timing out when editing or adding a new page/custom post
  80. Uploading files in admin panel?
  81. turn off new user registration emails
  82. Redirect Admin User in Dashboard
  83. Send automatic mail to Admin when user/member changes/adds profile
  84. Create un-removeable user
  85. Get current active wp color scheme
  86. Read only capability for custom post in admin area
  87. WordPress Admin back-end – advanced options page?
  88. Cannot login to WordPress Admin with SSL terminated load balancer
  89. How can ‘admin_email’ be set?
  90. Set Featured Image programmatically (in admin) with JavaScript?
  91. Disable the post save process completely
  92. use add_settings_field properly?
  93. How to change WordPress default strings?
  94. How can we customize the logo and some text on the welcome screen?
  95. front end logo upload like happytables
  96. Can I set a default dashboard layout for all users?
  97. Allow admin login at /admin
  98. Is there a hook to put stylesheet and/or JS inside iframes (thickbox or tinyMCE) in admin area
  99. How to add filter in “Comments” at the admin panel?
  100. Thickbox hacking – removing fields
Categories admin Tags admin, wp-login-form
wp_insert_post featured image from library
Is there a hook or a function for multisite blog deactivate or delete?

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