WordPress has a function to check if user is logged in or not.
is_user_logged_in()
You can use this function with conditional statements to restrict not logged in users from accessing contents.
for example if you want to restrict the homepage for not logged in users you may do this with following code.
function annframe_restrict_access() {
if( is_home() || is_front_page() ) {
if( ! is_user_logged_in() ) {
wp_redirect( home_url( 'page-name' ) );
exit();
}
}
}
add_action( 'init', 'annframe_restrict_access' );
Related Posts:
- Redirect to requested page after (custom) login
- Redirect all pages to the custom login page except for the registration page
- Change the login button on the login page
- Custom ReCaptcha Login
- What is the proper way to apply the login_form_bottom filter?
- How to override wp-login.php
- Remove Links from Login page
- Need logged in users returing to site redirected to a separate page
- How to let a single post have its own domain name
- setting a specific home page for logged in users
- Redirect members to custom page upon logging in through WP admin
- Change “logged in” link in (you must be logged in to post a comment)
- Customizing the default logout page of WordPress
- How do I remove the eye icon that shows visibility on login screen and reset password screen
- Hide Login information in Account settings in Buddy Boss
- Custom Login and Registration form in Ajax
- Last time a user logged in
- How can I allow access to multiple users, using the same login, at the same time?
- WordPress custom login page
- Turn off redirect to canonical domain (or host website on any hostname)
- Adding a login form that concatenates three fields into a username
- Search result page redirect ex.com/?s=searchterms to ex.com/searchterms
- Properly customizing login/register form
- How to add an extra variable to login and authenticate it?
- Login/Logout Session Sharing – Multiple WordPress Installations
- Custom login with external provider iframe and data object
- Deep customization of wp-login.php
- User can not login
- Lost password empty field error redirect to custom login
- Custom Log In Screen – Disable password recovery [duplicate]
- Multi-site User Sessions
- How To Load an HTML File As A WordPress Page (With No 301/No Redirect)
- A truely custom login page?
- Switch between WordPress websites easy for an end user
- Lost password and back to blog in same line
- I w’d like to know If there are simple solutions to integrate other CMSs to wordpress
- How do I create a root link in wordpress to a PDF file?
- Custom login and registration forms
- Showing different pages depending on a cookie value
- URL and Site title outputting on Login page
- Is it possible to integrate a custom login feature with wordpress?
- How to change the login page without a plugin and not only customizing logo and text around the form?
- Removing “Failed” query argument upon successful login
- Validate user login in php
- how to change the url rediction of the woocommerce login page of the flatsome theme for my own in wordpress?
- Block direct access to thank you pages
- How to change Login default blue admin color?
- Latest update broke my custom login CSS
- Custom Route Returns 301/Passing Variable from Input
- Trouble with custom login page
- Wrap WordPress Login Form in custom Div
- Custom login doesn’t stay
- Check get_post value after wp-admin login
- where can i find the login page in wordpress and add my header to it
- Change the default WordPress image on the dashboard login to a custom image [duplicate]
- Redirect Every Instance of The Author Template Pages to Custom Author Pages
- Allow arbitrary text after page URL
- Pass the post ID
- How to request login for user but not for bots
- Show Site Name on WP login screen
- how to manage Session in WordPress using custom login?
- How to stop login for SPECIFIC users BEFORE a specified date
- Redirection after Category Change for Custom Structure
- Must I rewrite the whole login form or can I jsut do a part
- WordPress pagination with custom post type?
- How to retain visual breadcrumbs w/ tricky URL structure? Custom post template?
- 2.9 to 3.0: Pros and cons of upgrading?
- How do I create a Custom Post Box that Connects Different Posts Together
- How to replace blog page url with subdomain at all places, even in xml sitemap?
- Pull Latest Forum Posts within WordPress
- How to setup a membership system in WordPress?
- Where’s did this div element come from?
- query_posts meta_key with current date
- How to activate flash cards
- Add array of post id’s to a category?
- Transferring theme and imported post attachments
- Adding pub_Date to an RSS feed hosted on WordPress
- Get custom field value from not-current page
- Mimicking admin panel menu from wordpress 3.0.1
- RSS feed showing deleted post
- Personalized Gallery what are my options?
- saving the widgets position after drag and drop
- Custom page template, not acting as page
- Google calendar in wordpress showing events
- How can I resolve a .htaccess internal server error setting up a WordPress multisite?
- Trying to use .htaccess to redirect /profile to /login-2?action=profile
- how or where wordress collect unlogged user session
- How to create social Share Buttons Without Plugin
- Customize Widget Navigation
- Login redirect to previous page
- CPU overload spam – redirect link to wp-admin and new post
- Is it possible to add custom badges to product attributes conditionally, based on custom field?
- wp_enqueue_script JS code runs too late (after user begins interacting)
- Created Custom Block – When I come back to edit post/page and change my block content – Update button stays disabled
- Hook before user is created and make some custom validation
- I found this code to be very useful, how can I change it to a text that display “Product versions and period of last update” rather than a button?
- Set redirect for need login
- How do I make Dynamic Student Admission Form?
- WP Search Form Query: Add Author’s posts into search query
- Prevent WordPress from automatically installing a new theme each year