下面是一个用于显示登录/注销和注册URL的函数
//Add login/logout link to naviagation menu
function add_login_out_item_to_menu_wpa84418( $items, $args ){
//change theme location with your them location name
if( is_admin() || $args->theme_location != \'LOCATION\' )
return $items;
$redirect = ( is_home() ) ? false : get_permalink();
if( is_user_logged_in( ) )
$link = \'<a href="\' . wp_logout_url( $redirect ) . \'" title="\' . __( \'Logout\' ) .\'">\' . __( \'Logout\' ) . \'</a>\';
else {
$link = \'<a href="\' . wp_login_url( $redirect ) . \'" title="\' . __( \'Login\' ) .\'">\' . __( \'Login\' ) . \'</a>\';
if (get_option(\'users_can_register\'))
$link = wp_register(\'<li>\', \'</li>\', false) . $link;
}
return $items.= \'<li id="log-in-out-link" class="menu-item menu-type-link">\'. $link . \'</li>\';
}
add_filter( \'wp_nav_menu_items\', \'add_login_out_item_to_menu_wpa84418\', 50, 2 );
只要确定你改变了主题
LOCATION
使用您的位置名称