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() { // List of pages to redirect for non-logged-in users $restricted_pages = ['dashboard', 'my-profile', 'messages', 'bookmarks']; // Get the current requested URL path $current_path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); // Check if the user is not logged in and trying to access a restricted page if (!is_user_logged_in() && in_array($current_path, $restricted_pages)) { // Redirect to the login page wp_redirect(home_url('/custom-login/')); 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.