OhhMuaOhhMua
  • Home
  • Hosting
    • Best Web Hosting
    • Free Web Hosting
    • VPS Hosting
  • WordPress
    • Solutions & Troubleshooting
    • Installation & Setup
    • Themes & Plugins
    • Security
  • Computer Tips
    • Gaming Errors & Solutions
    • PC Troubleshooting
    • Computer Hardware
  • Coupons & Deals
  • Contact Us
Reading: How to Change WordPress Login URL Without Plugins (100% Success)
Share
Notification Show More
Font ResizerAa
OhhMuaOhhMua
Font ResizerAa
  • Computer Tips
  • Hosting
  • WordPress
Search
  • Home
  • WordPress
    • Installation & Setup
    • Security
    • Solutions & Troubleshooting
    • Themes & Plugins
    • Troubleshooting
  • Hosting
    • Free Web Hosting
    • VPS Hosting
    • Best Web Hosting
  • Computer Tips
    • Computer Hardware
  • Coupons & Deals
Have an existing account? Sign In
Follow US
Copyright © 2024 ohhmua. All rights reserved.
OhhMua > Blog > WordPress > Solutions & Troubleshooting > How to Change WordPress Login URL Without Plugins (100% Success)
Solutions & Troubleshooting

How to Change WordPress Login URL Without Plugins (100% Success)

ohhmua
Last updated: September 9, 2024 4:06 pm
ohhmua
Share
4 Min Read
How to Change WordPress Login URL Without Plugins
How to Change WordPress Login URL Without Plugins
SHARE

To secure a WordPress website, changing the default login URL is, in my opinion, an essential step. Additionally, this was requested by a member of a group, so today I’m sharing a PHP code that helps you change the default WordPress login URL smoothly without using a plugin.

How to Change WordPress Login URL Without Plugins
How to Change WordPress Login URL Without Plugins

Advantages:

  • No impact on website speed
  • No need for plugins
  • No direct modification of the wp-login.php file, ensuring WordPress updates don’t affect the change”

Code to change the WordPress login URL
Please add the following code to the functions.php file of your child theme.”

// change the login URL for wp ohhmua.com

// define login URL.
define('PASSCODE','loginlink');

function mask_login_url(){
  // redirect to login page when passcode is verified
  if( !is_user_logged_in() && parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY) == PASSCODE ){
    wp_safe_redirect( home_url('wp-login.php?'. PASSCODE .'&redirect=false') );
    exit();
  }
  // redirect to dashboard if the user is logged in
  if( is_user_logged_in() && parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY) == PASSCODE ){
    wp_safe_redirect( home_url("wp-admin") );
    exit();
  } 
}
add_action( 'init', 'mask_login_url');

function mask_login_redirects(){
  if( isset($_POST['passcode']) && $_POST['passcode'] == PASSCODE) return false;

  // redirect to dashboard when /wp-admin is accessed and the user is logged in
  if ( (is_user_logged_in()) && (strpos($_SERVER['REQUEST_URI'], 'wp-admin') !== false)) {
    wp_safe_redirect( home_url("wp-admin"), 302 );
    exit();
  }
  // redirect to homepage when accessing /wp-admin or /wp-login and user is not logged in
  if ( (!is_user_logged_in()) && ((strpos($_SERVER['REQUEST_URI'], 'wp-admin') !== false) || (strpos($_SERVER['REQUEST_URI'], 'wp-login') !== false)) && ( strpos($_SERVER['REQUEST_URI'], PASSCODE) === false ) ) {
    wp_safe_redirect( home_url(), 302 );
    exit();
  }
  // redirect to homepage after logout
  if( strpos($_SERVER['REQUEST_URI'], 'action=logout') !== false ){
    check_admin_referer( 'log-out' );
    wp_logout();
    wp_safe_redirect( home_url('?logged-out'), 302 );
    exit();
  } 
}
add_action( 'login_init', 'mask_login_redirects', 1);

// Add hidden passcode field to the login form
function custom_login_hidden_field(){
  echo '<input type="hidden" name="passcode" value="'. PASSCODE .'" />';
}
add_action('login_form', 'custom_login_hidden_field');
// change the login URL for wp ohhmua.com end

In the line define('PASSCODE','loginlink');, replace 'loginlink' with the login path you want.

After adding the code, your login URL will be as follows:
https://yourwebsite.com/admin?loginlink or https://yourwebsite.com/wp-admin?loginlink, which means you just add ?loginlink.

Final note:
I have tested this code multiple times and it has successfully worked on my demo website, so you can use it with confidence. If you encounter any issues during the process, feel free to contact me.

You Might Also Like

My Google Discover traffic skyrocketed after I did these 10 things

How to Add a “Read More” and “Show Less” Button to Product Descriptions in WooCommerce

Blog, E-Commerce, or Forum? WordPress Covers Every Website Type!

How I Optimized Pagination and Skyrocketed Traffic

How to Pick the Ideal Blogging Platform for Your Needs

TAGGED:loginwordpress
Share This Article
Facebook Twitter Email Print
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Trending Stories

what is computer hardware
Computer Hardware

What is Computer Hardware? Everything You Need to Know

August 23, 2020
How to fix something went wrong in game uncharted 4
Gaming Errors & Solutions

How to fix something went wrong in game uncharted 4

September 23, 2024
How to Pick the Ideal Blogging Platform for Your Needs
Solutions & Troubleshooting

How to Pick the Ideal Blogging Platform for Your Needs

April 1, 2025
Guide to Choosing the Best Gaming CPU
Computer Hardware

Guide to Choosing the Best Gaming CPU

July 28, 2020
How to Add a Read More to Product Descriptions in WooCommerce
Solutions & Troubleshooting

How to Add a “Read More” and “Show Less” Button to Product Descriptions in WooCommerce

May 5, 2025
Change 0 Price or Empty Price to 'Call for Price' in WooCommerce
Solutions & Troubleshooting

Change 0 Price or Empty Price to ‘Call for Price’ in WooCommerce

September 7, 2024

You Might Also Like

Protecting Your WordPress Site from File Upload Vulnerabilities
Solutions & Troubleshooting

Protecting Your WordPress Site from File Upload Vulnerabilities

September 26, 2024
Title and Meta Description Mismatch on Google
Solutions & Troubleshooting

Title and Meta Description Mismatch on Google[How to fix]

September 25, 2024
Contact button
Solutions & Troubleshooting

Contact button in the footer with added call button shake effect

September 21, 2024
Guide to Creating a Beautiful Promotion Notification Box for Your Website
Solutions & Troubleshooting

How to Create a Stunning Notification Box for Your Website

September 20, 2024
Previous Next
newsletter featured

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

Follow US on Social Media

Facebook Youtube Steam Twitch Unity

Copyright © 2024 ohhmua. All rights reserved.

OhhMua

Information

  • About
  • Terms & Conditions
  • Privacy Policy
Welcome Back!

Sign in to your account

Lost your password?