If you would like to redirect unlogged user to custom login page (instead default login page) when he visits a page that requires being logged in (e.g. dashboard, messages, add listing etc.) you can use following PHP snippet.
You can add code into your functions.php file in child-theme or use WP Code plugin:
Here’s PHP snippet.
add_action('template_redirect', function() {
if (is_user_logged_in()) {
return;
}
$restricted_pages = ['dashboard', 'my-profile', 'messages', 'bookmarks'];
global $post;
if (is_page() && $post && in_array($post->post_name, $restricted_pages)) {
// Save the current URL to redirect back after login
$_SESSION['redirect_after_login'] = $_SERVER['REQUEST_URI'];
wp_redirect(home_url('/registration/'));
exit;
}
});
Custom Login Page
You can create custom login page using Elementor and login form shortcodes:
[listeo_login_form]– displays both login and register in a tabs[listeo_login]– only login form[listeo_registration]– only register forms
You can place these shortcodes on any page where you want the respective forms to appear. For more details, you can refer to the Shortcodes section in the Listeo Knowledge Base.