This is just a modification of timshutes’ answer – if you want specific pages to require login and don’t want to put them into a custom post type, you can add to functions.php:
add_shortcode('need_login', 'shortcode_needLogin');
function shortcode_needLogin() {
if (!is_user_logged_in()) {
auth_redirect();
}
}
And then at the top of the pages you want to require login for, you can just do:
[need_login]
Related Posts:
- Fetching private posts or custom post types via WP-API with basic authentication
- How to redirect to a passworded page based on password entered on login screen
- Set posts of a custom post type to be private by default?
- Forcing all posts associated with a custom post type to be private
- How to automatically apply a password to all posts within a custom post type
- My custom page template with is_user_logged_in() does not detect that I’m logged in
- Disable comments from showing up public for Custom Post Type
- Making a Custom Post type only visible to non-users via a specific link
- Exclude the_content (); from page password protection
- Comprehensively Restrict Post Type Taxonomy to Logged-in Users
- How do I get WordPress login to ignore the password input if a particular username is used?
- query private custom post type
- Private page protected with username and password
- Display content based on a users login
- How do I display content to users who are not logged in instead of 404 on Private custom posts?
- Giving permission to anyone (non-users as well) with a password to edit a post, possible?
- What is best way to prevent access to Custom Post Types unless authenticated when the post type has an archive and is publicly queryable?
- Custom post type permalink returns 404 when set to private
- wp-json API: not logged in when clicking link to the API from admin mode
- Have custom post type Visibility be private by default, and have radio button also set to “Private”
- Easiest way to have closed comments on a custom post type
- Forcing two or more custom post type to be private
- Password protection template and automatic fall in post type
- Check for empty username or password on login
- Advice on setting up private site
- How can I incldue a “private” post type in a loop for public users?
- Restrict Contributors to view only their own custom post types?
- Custom post status not working
- Add / Remove Post Type from “Link to existing content” popup
- How to programmatically create a connection with [Plugin: Posts 2 Posts] on cpt publish?
- Need some templating advice for templating with custom post types and taxonomies
- Adding a term name from a custom taxonomy assigned to a post link displayed by a wp_query loop based on another taxonomy
- Add New Post (Custom Post Type) Deletes 1 Post’s Custom Meta Data
- Insert slider (Custom Post Type) into pages
- get terms that have post with custom post type between 2 values
- Custom Scripts per page or Custom Post Type
- Custom Post Type not appearing in website search
- Loop through posts of a custom-post-type (event) and create .ics (iCal) file?
- Count posts with specific term_meta
- Custom search for custom post meta with pre_get_posts interferes with WP search
- Need to display same custom post type on 2 different singles templates
- get_posts of Custom Post Type AND Custom Taxonomy
- Tag page with Custom Post Types not returning any posts
- Get parent categories of custom post type
- Advanced or not so advanced pre_get_posts query
- Querying both pages and posts
- Pagination issue on category.php using custom post type query
- How to change permalink to include custom post type
- Pages are not saving due to custom post type
- save_post custom post type ? $_POST not working?
- Change the Custom Taxonomy URL Slug pattern
- Load Next WordPress Posts With AJAX?
- Add a custom meta box for client to order CPT posts how they want
- Add categories to a page with out using Custom Post Types
- Gravity forms multiple posts generated by one form [closed]
- Implementing Pillar Posts; Long Posts yet with Some Page-Like Handling?
- CPT Columns doesn’t show categories
- Role capabilities issue
- Custom Post Type “MUST NOT” be able to search via URL
- Custom taxonomy template list not working (404)
- Query for post and costom post_type in same category filtered by meta for post_type
- List latest post out of 2 custom post types
- Adding custom post formatting options in custom post types
- Calling related posts to a custom post type, taxonomy & Tag id
- How to get custom post type title, excerpt, thumbnail and permalink by post ID?
- Adding Page Ordering to a Custom Page Type
- How to properly use Categories with Custom Post Types
- Prevent user from editing others posts
- Better in the long run to use post date or custom taxonomy to sort/separate posts by year?
- Get post-meta value of all custom-posts – lowest to highest year-count?
- One Custom Post Type two different Templates
- Custom Post Type Query W/Category Dropdown
- On click some element i want to use some template
- Pin posts to top of custom loop
- Remove custom taxonamy slug with pagination
- How do I link to a dynamic ACF button from a Custom Post type?
- Hook create / update post
- Show Post columns to specific users on condition
- Change picture attachment meta of all occurrences of a picture
- Custom Taxonomy – fields
- CPT Loop, include taxonomies and disclude others?
- How to use costum database table for custom post type
- connect users to Custom post types
- Populate custom post type/custom fields from an external database
- Making my custom column sortable
- date_query won’t accept day parameter, but will accept month and year for a custom post
- the_permalink() leads back to homepage
- Custom Post Type Pagination Not Working or Single Posts Displaying?
- 404 error Custom search results page for custom post types with friendly URL
- Prevent repetitive terms in get_the_term_list
- Generate custom RSS from a plugin
- Custom metabox value not saving
- Category / Custom Post Type permalink issue
- Paged within a custom content type template [duplicate]
- is_singular won’t call my functions?
- loop through custom post-type with two meta_keys
- Generating custom URL before post is published
- How do i make a listing page of custom post type?
- How to add post type in masonry posts elementory widget
- How to exclude certain portfolios from a loop