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
- Remove WordPress theme from a specific page
- difference between esc_attr(), strip_slashes(), strip_tags()?
- Looking to display non-image files in Gallery with logo specific to file type
- Redirect to login page
- Is it ok to not a have child theme and just create a theme from scratch?
- How to Remove Subscribers from the Post Author Drop Down
- How do I redirect a user when he is logged in after clicking on a menu
- Why would switch_to_blog stop working?
- $wp_customize->remove_section for customizer setting?
- Search a post using the date it was posted
- Multiple Images/ Slider with custom post [single.php] [closed]
- How do I change the markup only of a built-in widget?
- Is it possible to make widget return only data (eg, array)?
- website with pretty permalinks except pagination
- How to create a control for css opacity in the Customizer
- add an option to the read page
- Custom Tags Archive – permalinks not working
- WordPress in a Subdirectory
- Change Site Logo or Menu Logo Per Page
- WP Admin Login keeps redirecting to login
- If Term Name Exists, Append a Unique ID to Slug
- How can I display both LTR and RTL language texts on the same page?
- New Page/Post Screen Opens an Existing Post
- Cannot go to next page on phone but can on computer
- A specific menu inside a page, load different contents without reloading it, under the same link
- How to hide or remove a custom widget area when empty
- Dockerized WordPress is having Nginx Proxy Issues
- Create single{custom}.php with data in table out of wp_posts
- Highlight specific user with custom field value
- Custom Login Plugin Redirects to wp-login.php After Site Migration
- let users add multiple divs in static page
- Best way to replace image url with source
- Multiple Taxonomies Using Custom SQL Query
- Pull certain WordPress posts on custom CMS instead and 301 wordpress to it?
- Create users via PHP
- Show post content in two different places without redirect
- Applying my own css classes in wp_menus 3?