You can modify the above code to check for the pages you want to be accessible, else redirect to login:
if (!is_user_logged_in() && $GLOBALS['pagenow'] !== 'wp-login.php' && !is_page(array('page1', 'page2', 'page3')) )
You can check the documentation for is_page here: https://developer.wordpress.org/reference/functions/is_page
Related Posts:
- wp_enqueue_script was called incorrectly
- Using a private method as an action callback from within a class
- Masking logout URL
- How can I tell if I’m on a login page? [duplicate]
- Is it possible to use a forgot password url filter?
- Attach a private function at a hook?
- redirect wp-login.php to another page
- Login using the password from protected pages
- display public excerpt for private post
- How do I redirect upon login a specific user based on role?
- Logging in redirects to correct page but shows logged out content until forced refresh
- Remove default user registration, login and subscriber profiles
- is_user_logged_in not working to redirect only logged out users
- Members only site – still need the lost password page accessible
- How to change login labels
- How can I get my Script to work on the Login page?
- Login Redirect if Logged in from Specific Page
- Unable to login using username
- When a user logs in, how can they view the website instead of the admin menu?
- WordPress PHP Conflicting User Sessions
- Allowing users to view private posts (pending approval)
- Get User Login Data (date, time… )
- Registration Hooks don’t appear to be working
- If user is logged-in display/hide something
- Secondary Menu and Logged In Users
- Prevent WordPress Automatic Logout
- error at login page in wordpress
- Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
- Logout Redirect and also WP-login.php Redirect
- loginout function customization
- Add Login and logout buttons to top menu bar
- Show errormessages on wrong username/password on custom loginform?
- WordPress login set cookie that survive browser exit (wp_signon function)
- This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise
- Prevent wp_signon redirect on failed login for ajax login
- How to redirect Subscribers on login to specific page, when logging in from a Page
- How to replace ACTION url from original wordpress login form?
- Unable to login after registration
- Allow logged in user to view a Page, else send to login screen and then redirect back to Page
- Redirect after login to current URL
- Login functions
- WordPress permanently logging users out
- How to request login for user but not for bots
- is_user_logged_in() isn’t working
- update_user_option not working as expected
- “Headers already sent” while trying to add a CSS file to my login page?
- How to override parent functions in child themes?
- Define page template in wp_insert_post
- How to remove Customize from admin menu bar after WP 4.3
- Child theme functions.php do I use php open and close tags?
- why doesnt is_home() work in functions.php
- Enabling shortcodes for custom fields
- Passing variables to templates (alternatives to globalizing variables)
- Load post with a different template?
- Two different menus for two different locations?
- Most efficient way to get custom database records from 20 buttons and 20 tables?
- Empty Date Returned on my function
- Woocommerce Attributes pulling in wrong data
- How to get the post_name when in preview?
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Echo tags used to describe the theme
- How to Display Frontend CSS for Administrator only
- How can I change a function in a parent theme via a child themes functions.php
- Automatically assign video ‘poster’ value to ‘filename’ for archive listing
- How can I make a widget shortcode to control all the widgets?
- Unique sequential reservation code
- Where to add the permalink in this function?
- Always the Latest google jQuery instead of default WordPress jQuery
- Override the WordPress core function wp_referer_field
- Control the srcset much more (not all sizes in it each time)
- Warning: join(): Invalid arguments passed in post-template.php
- Can’t locate custom image sizes defined by child theme
- how to change “posted by” words
- Add attribute only to first image of every post via functions.php
- 400 Bad Request – JavaScript App calling Custom wp-json endpoint
- Add loggedout class on body using a function or JS
- Help with IF has focus then… statment
- How d0 i get the number of attachments in the post
- Default click “I have read and agree to the website terms and conditions”
- How to use wp_enqueue_script properly?
- Enqueue script if not page template
- How do you insert code into the sidebar?
- Images with overlay
- Combine multiple menus using the filter wp_nav_menu_items
- Changing author links on homepage to buddypress profiles – without affecting ability to link to author archive throughout the site
- Comment function for page
- Taxonomy On Index Page
- Zip all (original) images from media gallery
- How to exclude posts with empty and non-existent relational custom field with meta_query?
- How to replace words in my posts and saved new words
- Problem in shortcode outputting content
- How to use different jquery function of idangero swiper dependant on page template?
- Why does modifying my functions.php file always result in a server error
- Echo custom field value in shortcode function
- WordPress Comment functions
- wp_get_current_user->user login returns %20 for spaces
- Disable every rss feed except home feed
- Explode Array from Repeatable Custom Field
- CF7 Remove Comma from ‘select’ ‘radio’ and ‘checkbox’ outouts
- Timeline from diferent wordpress api urls endpoint works, but diferent date