[英]Replace wp login with custom login page
I'm using a snippet to add a login/logout button to my sites nav menu. 我正在使用一个代码片段向我的网站导航菜单添加一个登录/注销按钮。 I want to change the login link to my custom page "/login"
我想将登录链接更改为我的自定义页面“ / login”
I added the last section so that logging out will redirect to the home page. 我添加了最后一部分,以便注销将重定向到主页。 I don't know what to replace to change the login link.
我不知道要替换什么来更改登录链接。
add_filter('loginout', 'loginout_selector');
function loginout_selector($text) {
$selector = 'class="logout-link" style="font-size: 0.85em, text-align: center;"';
$text = str_replace('<a ', '<a '.$selector, $text);
$text = str_replace("Log out", "Logout", $text);
return $text;
}
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
ob_start();
wp_loginout('index.php');
$loginoutlink = ob_get_contents();
ob_end_clean();
$items .= '<li style="list-style: none; text-align: center;">'. $loginoutlink .'</li>';
return $items;
}
//redirect to homepage after logout.
add_action('wp_logout','unlog');
function unlog(){
wp_redirect( site_url() );
exit();
}
wp_loginout('index.php') will redirect to default wordpress login page. wp_loginout('index.php')将重定向到默认的wordpress登录页面。 if you create the custom login page customize the wp_loginout function.
如果创建自定义登录页面,则自定义wp_loginout函数。
you can do like. 你可以喜欢。
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
/************************************************************************
1- If user is not login, When click on login button will redirect to site_url()/custom_login_page
2- With button you can add your custom class
*****************************************************************************/
if ( ! is_user_logged_in() ) {
$link = '<a href="' . site_url() . '/login">' . __( 'Log in' ) . '</a>';
}else {
$link = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>';
}
$items .= '<li style="list-style: none; text-align: center;">'. $link .'</li>';
return $items;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.