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

Redirect user to login before viewing custom post

You could set up a child theme, and in the single-listing.php template, add conditions around the current code.

<?php
// If the user is not logged in, redirect
if ( false == is_user_logged_in() ) {
    wp_redirect( wp_login_url() );
    exit;
}
// Else the user is logged in; show the listing
else {
    // Paste the regular template code here
}
?>

Everything else will remain public, while just the individual listings will force the user to be logged in before they can view the content. (This will also prevent search engines from seeing the content, so bear that in mind.)

Related Posts:

  1. Redirect User to Homepage if no other redirect is specified
  2. Redirect subscribers to last viewed page after log-in
  3. How to check User Role and redirect to specific page according to Role when login in WordPress?
  4. how redirect users to custom login page when “login to reply” is clicked? [duplicate]
  5. Specific Content on pages based on user
  6. Redirect based on log-in status per JavaScript
  7. Replacing the WordPress password validation
  8. WordPress auto login after registration not working
  9. Allow up to 5 Concurrent Login Sessions
  10. Why does is_user_logged_in() return false after redirect from another site?
  11. Pre-populate Username Field
  12. Redirect after User Activation [closed]
  13. Redirecting user after updating profile?
  14. How to keep track of user logins?
  15. Get user info outside WordPress
  16. How can I secure a WordPress blog using OpenID from a single provider?
  17. Is it possible to get a user with just the password field?
  18. Redirect after login based on user role (custom login page)
  19. Check for user meta data at Login
  20. My custom page template with is_user_logged_in() does not detect that I’m logged in
  21. Use phpbb user database for WordPress
  22. WordPress to use Drupal users’ credentials
  23. Redirect after users complete profile form
  24. Share user table from WP with Drupal
  25. How can I allow password reset based on logins containing the @ character?
  26. A way to count logged in users and display count?
  27. stop login if user_status equal zero
  28. Hide everything on site for visitors except specific page IDs
  29. Rule to redirect non logged in User to Custom Registration/login Page in .htaccess file
  30. How do i make my wordpress website private?
  31. Change the user_login at registration
  32. Max no of simultaneous active sessions for a single user
  33. When I try to login in wordpress it is showing “USER Doesn’t Exists”
  34. Should I encrypt the response that triggers an Ajax action? Is nonce sufficient?
  35. Redirect user after successful email change
  36. wordpress disable login for unverified user
  37. WP_User_List -> How to open a new edit-page in WordPress admin backend!
  38. Reset Password policy
  39. Rewrite Rules and Login Issue
  40. Is possible to allow user to login with different role?
  41. How to stop redirect if user is already on correct page (Using Case Switch)
  42. Use WordPress Login for a non-wordpress site
  43. WP not logging in at first time
  44. WordPress Login Customization for External Authentication
  45. How to allow registered users to submit the form only 5 times per day?
  46. Does wordpress support natively the concept of logging-in users? (not admins, but users of the website)
  47. Is there any action /filter hook I can use to disable login for some user role?
  48. Display video on homepage for users who have not logged in
  49. How can I do a url redirect to include a wordpress username?
  50. How do you manage your pages or functions that require logged-in users?
  51. Redirect logged on user to a specific page based on wp user role, page id
  52. How can i login with user’s password in WordPress being an admin?
  53. Should I setup frontend-only users as CPT or use a plug-in?
  54. Delete a user from frontend
  55. Redirect users after login
  56. Redirect user to login if not logged in, on specific pages
  57. Check if user is logged in via JS? [duplicate]
  58. redirect user to their profile after log in
  59. Use members from 1 site on another one
  60. WordPress Redirect Specific User. Tired of Peter’s redirect Plugin its not working
  61. Can I edit the database to change a login?
  62. Redirect current user to their most recent custom post
  63. User(s) already exists show error please provide a valid username
  64. wp_generate_password sets password but can’t login using created password
  65. Janrain/Simple Modal under Redirected Domain
  66. add class to element if user is not logged in [closed]
  67. Is there a way to call via javascript if a user is logged-in on a static html file?
  68. Restricting wordpress login sessions for a web app
  69. How to remember which page the user was on before logout?
  70. How to connect wordpress user with my own APP user?
  71. How to change default username field after login
  72. The same session information for peer users on two different WordPress servers
  73. WP users cant reset password
  74. Check for empty username or password on login
  75. Redirect /member/ to /member/user
  76. $user_login is not working if author has only 1 post
  77. How to use url formatter with integer
  78. user and usermeta table not found
  79. Redirect current user
  80. custom login form, guide me
  81. Front end login and page restriction
  82. Changing user_login ends current session
  83. Current User Seeing Another Logged In User Info
  84. Securely log in a user without a password using a link?
  85. Integrating Facebook Registration (and Login) on a WordPress page
  86. WordPress – Security Question at Login from User’s Meta Data
  87. Redirect user based on role when they try access a particular page
  88. determine active user browser at the same time
  89. How to track all users logged into a site?
  90. Cant edit profile from frontend
  91. How to authenticate/verify login credentials & check for user meta without logging in?
  92. Will users still be able to log in if I change host?
  93. redirect to my login page if not logged in
  94. Does WordPress Importer notify imported Users?
  95. How can I attach a user to another user with user meta
  96. Login Redirect if Logged in from Specific Page
  97. Want to know who is login Admin/User
  98. How to display extra fields for user
  99. Disable editing profile for second time
  100. How is user visits calculated
Categories users Tags content-restriction, login, redirect, users
Admin search not working for any type of post
wordpress api using rest_route for other pages

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