Hi @gamicord,
To prevent users from accessing the default WordPress login page (wp-login.php) and the admin dashboard (wp-admin), you can use a PHP code snippet to redirect them to a custom login or registration page. Add the following code to your theme’s functions.php file or in a custom plugin:
<?php
function custom_login_redirect() {
// Check if the current URL contains "/wp-admin" or "/wp-login.php"
if (strpos($_SERVER['REQUEST_URI'], '/wp-admin') !== false || strpos($_SERVER['REQUEST_URI'], '/wp-login.php') !== false) {
// Redirect to your custom login or registration page
wp_redirect(home_url('/your-custom-login-page')); // Replace with the actual URL of your custom login page
exit();
}
}
add_action('init', 'custom_login_redirect');
?>
Thanks!
@harshgajipara
Thanks for this Code. I appreciate your effort to help.
Now, this code works. But it works in a very terrible way.
I am logged in, before I inserted the code. The page slug I want users directed to, is the “my-account” Page.
When I click Logout, it doesn’t log me out. It continues to keep me fixed and Logged in, inside the “My-Account” Page.
2.) When I first inserted it through functions.php, it told me that it couldn’t find a way to check with server.
See the message and error report here— https://prnt.sc/NRJy0NgPtZWz
What do you think could be wrong in the code?
How do we fix it, and make it usable?
Needing to hear from you soon.
Regards.
Hi @gamicord,
Can you please try inserting code using SFTP if you have or try using this plugin to insert the code snippet and check again if that works?
plugin: https://wordpress.org/plugins/code-snippets/
Thanks
This is the plugin I always use to insert code: https://wordpress.org/plugins/insert-headers-and-footers/
Once the code gets added, I can’t logout again. It just keeps me fixed and logged in, with logout no longer possible.