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?
- pre_get_posts with multiple post types AND a meta_key
- Display custom Taxonomies same as listing Categories
- Test for post type in request filter?
- redirect old post type url to new structure url
- How can I add a “fake” parent into the permalink?
- Search form to find custom meta box generated data
- What kind of post type structure do I need to manage a list of ranked skills?
- Custom Post Type + Category archive
- Problem with ‘save_post’ hook not running
- Calling specific page with wp query
- Customizing a plugin function using a hook
- How to make post page unique and show it on home page?
- Trying to modify custom search function in plugin to search postmeta table for keyword as well as posts table
- Custom Post Type Audio Content
- current_menu_parent for custom post type and custom url
- Changing custom post_type when publishing
- Custom post type taxonomy not sorting correctly
- Pagination in custom post type page template
- Customising the admin columns for a custom post type, but now most of the built in categories don’t display?
- Post is not being published after clicking on Publish button in Custom Post Type
- WordPress custom post type
- How to get Last post Id of custom post type in wordpress
- group posts by month/date ignore years
- How to get main div html to print a list of posts inside?
- Attach a custom post type archive to a static page
- erase post excerpt limitation [×]
- How to have working breadcrumbs with several taxonomies associated with a custom post type
- wp_lostpassword_url not escaped
- Custom Post type archives / categories give 404
- Custom Post Type with /%shop_name%/gallery/%gallery% permastruct?
- Custom Post Type URL Rewriting
- Modify shortcode to work with custom taxonomies and slugs
- Sorting on Taxonomy in archive page
- Calling the first & last post by category in custom post type
- Get list of CPT posts in *current* post’s taxonomy term
- Organizing The Custom Post Type with Taxonomies / Parent Posts
- Shared Custom post type between WP network sites
- Custom Info Box at end of posts?
- Would like to add a “leaderboard” (custom field) to a custom post type
- show custom taxonomies in hierarchy
- Loop with Custom Post Type and Taxonomies
- How to get past and upcoming post by defining date in custom field?
- Remove sequential number from permalinks
- How can I include custom post types on a tag page?
- custom post type archive slug vs. custom page template
- Pagination fault in custom post type archive page [duplicate]
- How can I convert custom posts types into regular posts?
- How to stop wp_query searching pages as well as the specified CPT
- Custom post types archive
- Display 2nd category, only once, as sub-heading, in the loop
- Custom Post Types and Pre Populated Custom Taxonomies
- WordPress custom post type queries
- Render custom taxonomy query as single template
- Query posts from multiple post types sorted by overarching menu order
- How to add gallery support to a custom post type?
- How to display data with pagaination on backend?
- Site loads very slow for archive custom post type page
- Converting a checkbox filter for custom fields to a dropdown
- How can i call a custom method on submission of a custom plugin post type?
- Set the Title of a Custom Post Type by code as Author’s Username
- Custom meta-box for all custom post types
- Custom Taxonomy Query by Taxonomny not working
- WordPress: insert a custom post type instance as an option for a custom taxonomy
- Edit post meta direct from post.php?
- Fetch posts list from fist CPT taxonomy term and list under 2. CPT
- Front end page submission form does not attach custom post type
- Custom Post ‘Post Per Page’ Crashing Page?
- Pagination custom post types outside loop
- display news with pictures 3 small and one large (loop)
- Create an additional template page for every term taxonomy
- How to get $post object available inside functions.php to localize script?
- How do I get a nested query to only display content that the main query outputed
- How to add elements to WordPress appearance->menu admin?
- shortcode order for event custom post type