One way of doing this would be to add the code below to the top of your template file(s):
<?php // redirect to login page if user is not logged in
if ( !is_user_logged_in() ) :
header('Location: /wp-login.php');
exit();
endif;
?>
There are some subtleties around redirecting in PHP that you may want to consider, but for me the above code works.
Related Posts:
- User restricted only show posts assigned to current user
- How to restrict an admin page, if the user is not superadmin?
- wp_update_user not updating
- Is WordPress’ is_user_logged_in() secure?
- Temporarily disable user role login and replace with message
- how to add custom user capabilities using add_user_meta or something else?
- Is there a way to set the user Role based on email domain
- pre_get_posts Remove posts based on meta value with ‘post__not_in’
- What is the difference between “create_users” and “add_users” capabilities?
- Access on specific pages in wordpress for a specific user
- How to ‘unpublish’ or ‘hide’ posts when user role changes?
- Hide Specific User Page
- Let new user role to ‘edit_others_posts’ of other user role, not of its own type
- How can I have different groups of editors only allowed to edit certain parent+subpages?
- Hide everything on site for visitors except specific page IDs
- How do I remove the Other Roles field (from User Role Editor plugin) in wp-admin/user-new.php
- How to redirect specific post type with user role
- wordpress editor role remove all but ‘menus’ in appearance menu
- Parent User and Child User – relate users
- How to create user specific pages (not user role!)?
- Assigning certain authors to specific editors
- Restrict Access in Admin Panel
- Limit a user to have access to only specified pages?
- Plugin creation – how to add user rights?
- Restrict custom post content to specific user
- Need to block user role from accessing bbPress all together
- How to create a front facing user sign up, log in and profile pages like FoodGawker.Com [closed]
- Infinite redirects at front end if logged in user is not an Admin (Toolset Access)
- Is there a way to allow users with “Subscriber” user role to access media library in backend and frontend
- How to make WP page accessile only to specific user roles
- Custom user roles are unable to login
- grant multiple roles access to specific admin menu item
- How to show private pages based on a user’s role?
- Check what capabilitie(s) an action requires
- Redirect non-admin after login, and in url – /admin
- Is it possible to restrict a specific user to edit a specific custom post.
- Assign specific editor with custom user meta “A” to all authors with custom user meta “A” and exclude all other author access
- New folder and file permissions are not correct
- How to change user role setting in members plugin so that user can only edit his own post?
- How to restrict content on a subdomain to users that registers on main site?
- What do unfiltered_html and unfiltered_upload actually filter?
- Temporary capability for current_user_can()
- Code needed to only show users own posts in a multi-user account
- Restrict Author to pick from media library, but not upload media
- Remove Ability for Administrators to Delete Administrators
- Order users by custom user meta
- Auto Delete Users (auto_delete_users)
- New Roles and Capabilities in WordPress
- Issue with front-end ajax, getting a 302 redirect when accessing wp-admin/admin-ajax.php
- WordPress Super Admin
- Can’t manage to make translate_user_role() work
- how to assign more permission to wordpress author
- Limit users by custom taxonomy and user roles
- Restricting frontend acess based on user role otherwise redirect to login form
- Managing Users and Creating Groups [closed]
- Customizer – Allow user editor to change website title and tagline
- Query users which have same dynamically generated roles as the current user
- change role of wordpress users when they edit profile
- How to restrict CPT post’s fronted view only for specific user roles?
- Change post status based on user role
- Display User Role Next To Comment
- Allow an editor to change the author
- Protect sequence of pages with same password for each of two groups of users
- How to give remove role editing permission from user
- How can I allow an User to publish only 5 posts per month?
- How to have kind of a technical writer role in wp website
- Where are $current_user->allcaps set?
- How to make the Newsletter plugin visible to users with author privileges?
- WP welcome email depending on user role
- How can I promote a user to a network administrator?
- How to set where user is redirected to after logging in at wp-login?
- read_private_pages capability not working for new role
- How to change footer or for different kinds of users in wordpress?
- Grant a person permission to moderate all comments on a blog without giving them the ability to edit other peoples post
- How can I programattically hide all admin notices for everyone except admin users
- What Capability is required to let a role RUN code in Edit Theme?
- Restrict the list of parent pages to only those which are created by current user
- Can I Create a Second Admin Level User Role?
- Retrieve user roles but exclude default roles
- Disabled delete_others_posts if post is from admin
- How to hide Add new Term area for taxonomy terms for specific role (Client)
- show the author’s role along with the name in the single.php
- How to create different views for different user roles?
- How to Enable registration email for a custom user role?
- How can I add the ability for a user to add/edit administrators?
- add user role selection to registration form [duplicate]
- Front end login and page restriction
- Grant access to admin menu?
- I want this code to work only for Authors AND Contributors
- You do not have permission to access this document on form submit
- Disable Woocommerce checkout based on user role [closed]
- Remove_role not working, gives “Call to undefined method stdClass::remove_role()”
- Adding a new role with administrator’s capabilities
- Front-end ajax problem all users and guests getting a 302 redirect when accessing wp-admin/admin-ajax.php
- How to assign a custom gender to a user role?
- assign roles to users in custom drop down in signup form
- Hide block of HTML if the users role is a certain role
- How might I enable a user to view Draft pages from a different Author, without the ability to edit?
- Display users by role
- disable adding new tags on the edit and add post