You can do this way
function block_access() {
if (is_page (blog) && !is_user_logged_in ()) {
$loginUrl = home_url('/login-page/');
wp_redirect($loginUrl);
exit();
}
}
add_action( 'template_redirect', 'block_access' );
Related Posts:
- Do I need an empty page for a different blog page?
- Showing “best posts” in front page
- Programmatically set page_on_front
- How to make my front page display only the most recent sticky post, plus usual widgets?
- How do I set the front page programmatically?
- Custom background for the index page only?
- Load front-page.php from subfolder
- Can you select a post as the front page or only pages?
- How to display blog posts on a dedicated page?
- Can’t edit front page of website [closed]
- Setting a static home page and blog page without using the settings
- Pagination not Working on only Front page on latest verson of WordPress
- Create a front page template and separate page for posts?
- Showing option when page is frontpage
- Is it possible for homepage in Twentyseventeen theme to look like a standard page?
- WordPress site front page fails to load in IE
- Home/front page won’t display content after a form is submitted
- how to create a static front page for my blog in wordpress
- Home link in the homepage of my wordpress does not show my blog posts
- WordPress, how to figure out how to edit front page
- How to set a static html front page
- Why: sticky front page code, shows latest non-sticky on logged-in front page
- NON Static-Front Page
- Front Page Settings
- What code controls the animation for the front-page header in TwentySeventeen
- Setting index.php as a static home page without posts?
- Implement a slideshow-like frontpage with text overlays
- Pull in content from page defined as static front page
- Excluding front_page from is page condition
- Why does my site show the correct front-page when you arrive at the site, but not when you click ‘home’?
- Change Front Page Word Press 4.1
- custom change in front page [closed]
- Remove edit post link from static front page
- WordPress certain directories not connected
- Different front page for logged in and logged out user but the same URL in WordPress
- Homepage not working after setting as frontpage
- Hiding New Posts on Front Page
- change header height on 2017 theme for logged in users
- How to connect front-page.php to page in admin panel?
- Can I have two websites with one front page
- I created a new home page and set it as the home page in the reading section, but I get an error when typing in the home page url
- Categories with post from child categories on front page
- Static front page – going against the grain
- When Front page and Posts page are specified is it possible to just have front-page.php as the home page?
- Custom background for the index page only?
- No posts on front page
- How to display only sticky posts on my automatically generated front page?
- Front page welcome message area
- Static front page as parent of with child pages?
- How did WordPress link an empty page at dashboard to an actual php file?
- When to use is_home() vs is_front_page()?
- Check if current page is the Blog Page
- Allow member to have access to custom post type only. Permission to only edit their own posts
- How do I create a custom role capability?
- How to enable suggested edits?
- With Rest V2 (WP4.7) how does one restrict certain RESTFUL verbs?
- Using pre_get_posts on true pages and static front pages
- How to programatically change username (user_login)?
- How to check if user is in back end?
- Creating custom blog page template the right way
- How to restrict attachment download to a specific user?
- Filtering the Admin Comments List to Show Only Comments from the Current User?
- How can I create a “Read More” link using the_excerpt() on a static front page?
- How to restrict access to uploaded files?
- wp_update_user not updating
- is_front_page() malfunction?
- Show Default Editor on Blog Page ( Administration Panel )
- Allowing users to edit only their page and nobody else’s
- Can an admin check passwords of registered users?
- HTTPS leads to Sorry, you are not allowed to access this page
- How to add “Stick this post to the front page” to front end?
- How do I fetch the static front page using the REST API?
- Troubleshooting a “You do not have sufficient permissions to access this page” error
- Restrict admin access to certain pages for certain users
- How can I hide a category from Contributors in the edit/add new post screen?
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- Ways to have multiple front-page.php templates that can be swapped out?
- How to assign specific users the capability to edit specific pages / posts / custom post types
- Hide Admin Menu for Specific User ID who has administrator Role
- is_front_page only works in theme file, and does not work in functions.php
- What is the correct method for determining ‘is_front_page’ when using filters such as ‘pre_get_posts’ and ‘posts_where’?
- How to get all capabilities of an existing user role
- Allowing an email as the username?
- Make A WordPress Page Accessible To Admins Only, Redirect Other User Roles
- Limit access to posts/pages by user roles
- Allowing specific users to only add posts using certain custom taxomy terms
- Category page doesn’t use category.php, instead it redirects to homepage
- Is WordPress’ is_user_logged_in() secure?
- Website Visible only to Registered users
- How to put custom post types on front page
- Check if specific username is logged in
- I put my blog on a subpage, how do I get page title?
- ID for posts/blogs page
- How to prevent the default home rewrite to a static page
- Facebook comments box on front page
- Filter front page posts by category
- What is archive.php used for?
- How to manually activate user in dashboard only by admin
- How does WordPress decide what template to use as frontpage
- Post list based on the user that is logged in