wp_login_url

Home » Functions » wp_login_url

WordPress is a popular content management system that powers almost 40% of the web. If you’re building a custom WordPress login page or want to add a custom login link to your website, you’ll need to use the wp_login_url() function.

The wp_login_url() function returns the URL of the WordPress login page. By default, the URL of the login page is your website’s URL followed by /wp-login.php. However, using the wp_login_url() function ensures that the login URL is always correct, even if the admin has changed the default login URL.

This function is useful if you want to create a custom login link that redirects users to the WordPress login page. For example, if you have a membership site, you can create a custom login link that points to the wp-login.php page. You can also use this function in your theme files to create a custom login form or link.

Here’s an example of how to use the wp_login_url() function:

<a href="<?php echo wp_login_url(); ?>">Login</a>

This code will output a link that points to the WordPress login page. If you want to redirect users to a custom page after they log in, you can pass the URL of the custom page as a parameter to the function like this:

<a href="<?php echo wp_login_url( home_url( '/custom-page/' ) ); ?>">Login</a>

In this example, users will be redirected to the custom page after they log in.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.