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

Restrict content access to logged in users

WordPress has a function to check if user is logged in or not.

is_user_logged_in()

You can use this function with conditional statements to restrict not logged in users from accessing contents.

for example if you want to restrict the homepage for not logged in users you may do this with following code.

function annframe_restrict_access() {

 if( is_home() || is_front_page() ) {
   if( ! is_user_logged_in() ) {
         wp_redirect( home_url( 'page-name' ) );
         exit();
   }
 }

}

add_action( 'init', 'annframe_restrict_access' );

Related Posts:

  1. Redirect to requested page after (custom) login
  2. Redirect all pages to the custom login page except for the registration page
  3. Change the login button on the login page
  4. Custom ReCaptcha Login
  5. What is the proper way to apply the login_form_bottom filter?
  6. How to override wp-login.php
  7. Remove Links from Login page
  8. Need logged in users returing to site redirected to a separate page
  9. How to let a single post have its own domain name
  10. setting a specific home page for logged in users
  11. Redirect members to custom page upon logging in through WP admin
  12. Change “logged in” link in (you must be logged in to post a comment)
  13. Customizing the default logout page of WordPress
  14. How do I remove the eye icon that shows visibility on login screen and reset password screen
  15. Hide Login information in Account settings in Buddy Boss
  16. Custom Login and Registration form in Ajax
  17. Last time a user logged in
  18. How can I allow access to multiple users, using the same login, at the same time?
  19. WordPress custom login page
  20. Turn off redirect to canonical domain (or host website on any hostname)
  21. Adding a login form that concatenates three fields into a username
  22. Search result page redirect ex.com/?s=searchterms to ex.com/searchterms
  23. Properly customizing login/register form
  24. How to add an extra variable to login and authenticate it?
  25. Login/Logout Session Sharing – Multiple WordPress Installations
  26. Custom login with external provider iframe and data object
  27. Deep customization of wp-login.php
  28. User can not login
  29. Lost password empty field error redirect to custom login
  30. Custom Log In Screen – Disable password recovery [duplicate]
  31. Multi-site User Sessions
  32. How To Load an HTML File As A WordPress Page (With No 301/No Redirect)
  33. A truely custom login page?
  34. Switch between WordPress websites easy for an end user
  35. Lost password and back to blog in same line
  36. I w’d like to know If there are simple solutions to integrate other CMSs to wordpress
  37. How do I create a root link in wordpress to a PDF file?
  38. Custom login and registration forms
  39. Showing different pages depending on a cookie value
  40. URL and Site title outputting on Login page
  41. Is it possible to integrate a custom login feature with wordpress?
  42. How to change the login page without a plugin and not only customizing logo and text around the form?
  43. Removing “Failed” query argument upon successful login
  44. Validate user login in php
  45. how to change the url rediction of the woocommerce login page of the flatsome theme for my own in wordpress?
  46. Block direct access to thank you pages
  47. How to change Login default blue admin color?
  48. Latest update broke my custom login CSS
  49. Custom Route Returns 301/Passing Variable from Input
  50. Trouble with custom login page
  51. Wrap WordPress Login Form in custom Div
  52. Custom login doesn’t stay
  53. Check get_post value after wp-admin login
  54. where can i find the login page in wordpress and add my header to it
  55. Change the default WordPress image on the dashboard login to a custom image [duplicate]
  56. Redirect Every Instance of The Author Template Pages to Custom Author Pages
  57. Allow arbitrary text after page URL
  58. Pass the post ID
  59. How to request login for user but not for bots
  60. Show Site Name on WP login screen
  61. how to manage Session in WordPress using custom login?
  62. How to stop login for SPECIFIC users BEFORE a specified date
  63. Redirection after Category Change for Custom Structure
  64. Must I rewrite the whole login form or can I jsut do a part
  65. WordPress pagination with custom post type?
  66. How to retain visual breadcrumbs w/ tricky URL structure? Custom post template?
  67. 2.9 to 3.0: Pros and cons of upgrading?
  68. How do I create a Custom Post Box that Connects Different Posts Together
  69. How to replace blog page url with subdomain at all places, even in xml sitemap?
  70. Pull Latest Forum Posts within WordPress
  71. How to setup a membership system in WordPress?
  72. Where’s did this div element come from?
  73. query_posts meta_key with current date
  74. How to activate flash cards
  75. Add array of post id’s to a category?
  76. Transferring theme and imported post attachments
  77. Adding pub_Date to an RSS feed hosted on WordPress
  78. Get custom field value from not-current page
  79. Mimicking admin panel menu from wordpress 3.0.1
  80. RSS feed showing deleted post
  81. Personalized Gallery what are my options?
  82. saving the widgets position after drag and drop
  83. Custom page template, not acting as page
  84. Google calendar in wordpress showing events
  85. How can I resolve a .htaccess internal server error setting up a WordPress multisite?
  86. Trying to use .htaccess to redirect /profile to /login-2?action=profile
  87. how or where wordress collect unlogged user session
  88. How to create social Share Buttons Without Plugin
  89. Customize Widget Navigation
  90. Login redirect to previous page
  91. CPU overload spam – redirect link to wp-admin and new post
  92. Is it possible to add custom badges to product attributes conditionally, based on custom field?
  93. wp_enqueue_script JS code runs too late (after user begins interacting)
  94. Created Custom Block – When I come back to edit post/page and change my block content – Update button stays disabled
  95. Hook before user is created and make some custom validation
  96. I found this code to be very useful, how can I change it to a text that display “Product versions and period of last update” rather than a button?
  97. Set redirect for need login
  98. How do I make Dynamic Student Admission Form?
  99. WP Search Form Query: Add Author’s posts into search query
  100. Prevent WordPress from automatically installing a new theme each year
Categories customization Tags customization, login, redirect
Sitemap_index.xml is not displayed
How can i create menu like in the example?

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