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

Simple way to make most of my site private

You can modify the above code to check for the pages you want to be accessible, else redirect to login:

if (!is_user_logged_in() && $GLOBALS['pagenow'] !== 'wp-login.php' && !is_page(array('page1', 'page2', 'page3')) ) 

You can check the documentation for is_page here: https://developer.wordpress.org/reference/functions/is_page

Related Posts:

  1. wp_enqueue_script was called incorrectly
  2. Using a private method as an action callback from within a class
  3. Masking logout URL
  4. How can I tell if I’m on a login page? [duplicate]
  5. Is it possible to use a forgot password url filter?
  6. Attach a private function at a hook?
  7. redirect wp-login.php to another page
  8. Login using the password from protected pages
  9. display public excerpt for private post
  10. How do I redirect upon login a specific user based on role?
  11. Logging in redirects to correct page but shows logged out content until forced refresh
  12. Remove default user registration, login and subscriber profiles
  13. is_user_logged_in not working to redirect only logged out users
  14. Members only site – still need the lost password page accessible
  15. How to change login labels
  16. How can I get my Script to work on the Login page?
  17. Login Redirect if Logged in from Specific Page
  18. Unable to login using username
  19. When a user logs in, how can they view the website instead of the admin menu?
  20. WordPress PHP Conflicting User Sessions
  21. Allowing users to view private posts (pending approval)
  22. Get User Login Data (date, time… )
  23. Registration Hooks don’t appear to be working
  24. If user is logged-in display/hide something
  25. Secondary Menu and Logged In Users
  26. Prevent WordPress Automatic Logout
  27. error at login page in wordpress
  28. Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
  29. Logout Redirect and also WP-login.php Redirect
  30. loginout function customization
  31. Add Login and logout buttons to top menu bar
  32. Show errormessages on wrong username/password on custom loginform?
  33. WordPress login set cookie that survive browser exit (wp_signon function)
  34. This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise
  35. Prevent wp_signon redirect on failed login for ajax login
  36. How to redirect Subscribers on login to specific page, when logging in from a Page
  37. How to replace ACTION url from original wordpress login form?
  38. Unable to login after registration
  39. Allow logged in user to view a Page, else send to login screen and then redirect back to Page
  40. Redirect after login to current URL
  41. Login functions
  42. WordPress permanently logging users out
  43. How to request login for user but not for bots
  44. is_user_logged_in() isn’t working
  45. update_user_option not working as expected
  46. “Headers already sent” while trying to add a CSS file to my login page?
  47. wp_login_form display no styled form
  48. Redirecting after login except for a specific page
  49. Missing feature image link function
  50. What’s the difference between home_url() and site_url()
  51. Remove “Category:”, “Tag:”, “Author:” from the_archive_title
  52. get_template_directory_uri pointing to parent theme not child theme
  53. How to customize the_archive_title()?
  54. remove empty paragraphs from the_content?
  55. What is the “with_front” rewrite key?
  56. Why use if function_exists?
  57. How to override parent functions in child themes?
  58. Add multiple custom fields to the general settings page
  59. Ajax call always returns 0
  60. 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
  61. How long does a deprecated function live in core?
  62. Solution to render Shortcodes in Admin Editor
  63. How to add a data attribute to a WordPress menu item
  64. What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
  65. remove_action on after_setup_theme not working from child theme
  66. plugins_url vs plugin_dir_url
  67. Remove type attribute from script and style tags added by WordPress
  68. How to run a function every 5 minutes?
  69. Best way of passing PHP variable between partials?
  70. Upload Multiple Files With media_handle_upload
  71. How to display custom field in woocommerce orders in admin panel?
  72. Adding fields to the “Add New User” screen in the dashboard
  73. Issues with title-tag and document_title_parts
  74. How do I get the current edit page ID in the admin?
  75. How to check if a user exists by a given id
  76. Why isn’t is_page working when I put it in the functions.php file?
  77. Add tags to the section via functions.php
  78. Add image size if page template
  79. How to create a custom order status in woocommerce!
  80. Remove Actions/Filters added via Anonymous Functions
  81. Adding a second email address to a completed order in WooCommerce [closed]
  82. How to load parent_theme functions.php before child_theme?
  83. How to load scripts/styles specific for a page
  84. Programatically add options to “add new” custom field dropdown
  85. Is there any global functions.php file which works for any theme?
  86. Excluding iPad from wp_is_mobile
  87. Is there a is_user_logged_in() for multisite?
  88. When should you, and when should you not, use wp_list_pluck()?
  89. Get the ID of the page a menu item links to?
  90. Add container to nav_menu sub menu
  91. Difference between the_permalink() and get_permalink() function
  92. What’s the difference between WordPress random_int() and PHP built-in function random_int()?
  93. Child theme – Overriding ‘require_once’ in functions.php
  94. Link to user’s profile settings page?
  95. WordPress Enqueue for homepage only, functions.php, wp-framework
  96. get php variable from functions php and echo it in theme template files [closed]
  97. Get menu object from theme_location
  98. Is it ok to use a function to output the text domain name in a wordpress theme
  99. Displaying the number of updates available in the Admin area
  100. Trying to use add_action and do_action with parameters
Categories functions Tags functions, login, private
‘At a Glance’ dashboard: combining infos
Unwanted spacing for cover block

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