WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/login url

Description

login_url is a filter applied to the url returned by the function wp_login_url()

Parameters

$login_url
(string) (required) The URL for login.
Default: http://example.com/wp-login.php
$redirect
(string) (optional) The URL to redirect back to upon successful login.
Default: None
$force_reauth
(bool) (optional) Whether to force reauthorization, even if a cookie is present.
Default: None

Examples

The following example would return a login URL http://example.com/my-login-page/ for the wp_login_url() function:

add_filter( 'login_url', 'my_login_page', 10, 3 );
function my_login_page( $login_url, $redirect, $force_reauth ) {
    return home_url( '/my-login-page/?redirect_to=' . $redirect );
}

Same as above, but uses the add_query_arg() function for adding the redirect_to parameter and is expanded for readability.

add_filter( 'login_url', 'my_login_page', 10, 3 );
function my_login_page( $login_url, $redirect, $force_reauth ) {
    $login_page = home_url( '/my-login-page/' );
    $login_url = add_query_arg( 'redirect_to', $redirect, $login_page );
    return $login_url;
}

Change Log

Since: Version 2.8
Since: Version 4.2 The `$force_reauth` parameter was added.

Source File

login_url is located in wp-includes/general-template.php

Related