Hello, the technique demonstrated in this video is still effective to redirect a guest User to some URL. One main difference now is that some people use the Block Editor to edit Content Templates instead of the classic editor, but that won't effect the outcome here. The general process is:
- Create a Content Template and place the meta refresh HTML tag in that template using a classic block in the Block Editor, or in the main template code if you are using the classic editor. Modify the URL as needed to point to your site's login page.
- Create a post group in Access Control and select the redirection Content Template to show to Guest Users who don't have permission to view this group.
- Add your restricted posts to this post group.
If this technique isn't working for your site, I'll be glad to take a closer look. Please provide login credentials here in the private reply fields and I will review your setup.
> I want to lock the entire ste and redirect all users to the login page:
- The forum ticket that you referred to earlier and the login form's settings from your screenshot won't help you with this particular requirement.
For this, you'll need some custom code, which can check the current visitor's login status and then check the current page and redirect to the login page, if it is not one of the special excluded pages.
Example of excluded pages, which should be accessible to non-logged-in visitors are:
- Login page
- Register page
- Forgot password page
- Password reset page
Example code snippet:
add_action( 'template_redirect', 'redirect_visitors_to_login' );
function redirect_visitors_to_login( $template ) {
// if current visitor is not logged-in
if ( !is_user_logged_in() ) {
// list of pages to exclude from the redirect
$excluded_page_ids = array(12, 14, 16, 18);
// ID of the login page where visitors should be redirected to
$login_page_id = 12;
// if the current page is not among the excluded pages
if ( !is_page( $excluded_page_ids) ) {
// redirect to the login page
wp_redirect( get_permalink($login_page_id) );
}
}
return $template;
}
Please replace 12, 14, 16, & 18 with the actual page IDs of the excluded pages on your website.
Important note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors: https://toolset.com/contractors/