如何将WP注册/登录URL永久更改为我的自定义页面

时间:2016-11-06 作者:Shan Iqbal

经过大量的搜索和工作,我没有找到任何可以帮助我的东西,现在我想更改我的wordpress注册页面和登录页面的URL。我在这里添加了一个示例,您将看到我是如何想要登录页面的,wordpress是如何试图向我展示的。

enter image description here

但是wordpress会自动将我的页面重定向到另一个我也自定义的无聊页面,但我希望这是我的页面。我这样做是为了告诉你当我点击(注册或登录)url时wordpress的位置。

下面是,

enter image description here

1 个回复
SO网友:sMyles

只需使用login_url 过滤器:

https://gist.github.com/tripflex/ac477b59d20bd11c5856edcffc13e5ef

add_filter( \'login_url\', \'smyles_custom_login_url\', 10, 3 );
/**
 * Filters the login URL.
 *
 * @since 2.8.0
 * @since 4.2.0 The `$force_reauth` parameter was added.
 *
 * @param string $login_url    The login URL. Not HTML-encoded.
 * @param string $redirect     The path to redirect to on login, if supplied.
 * @param bool   $force_reauth Whether to force reauthorization, even if a cookie is present.
 *
 * @return string
 */
function smyles_custom_login_url( $login_url, $redirect, $force_reauth ){
    // This will append /custom-login/ to you main site URL as configured in general settings (ie https://domain.com/custom-login/)
    $login_url = site_url( \'/custom-login/\', \'login\' );
    if ( ! empty( $redirect ) ) {
        $login_url = add_query_arg( \'redirect_to\', urlencode( $redirect ), $login_url );
    }
    if ( $force_reauth ) {
        $login_url = add_query_arg( \'reauth\', \'1\', $login_url );
    }
    return $login_url;
}