从您的代码来看,您似乎正在使用此模式登录插件http://wordpress.org/plugins/wp-modal-login/ 考虑到这一点,我提供了必要的代码来将菜单项添加到菜单中。
您需要使用wp_nav_menu_items
内钩如下functions.php
活动主题的文件。
// Add the hook to the nav menu items
add_filter( \'wp_nav_menu_items\', \'wti_loginout_menu_link\', 10, 2 );
function wti_loginout_menu_link( $items, $args ) {
// Get the global object for user and the modal login class
global $current_user, $wp_modal_login_class;
if ( $args->theme_location == \'primary\' ) {
$items .= \'<li>\';
if ( is_user_logged_in() ) {
$items .= \'Welcome, \' . $current_user->user_nicename;
} else {
$items .= \'Welcome, visitor\';
}
// Add the modal menu to the nav menu
$items .= \' \' . $wp_modal_login_class->modal_login_btn( \'Login\', \'Logout\', \'\', false );
$items .= \'</li>\';
}
return $items;
}
Few things to note:
<上述代码适用于
primary
主题位置。您需要将其更改为主题位置。
我正在使用user_nicename
, 您可以使用first_name
用户对象的。
这里也讨论了上述挂钩http://www.webtechideas.com/adding-login-logout-link-to-wordpress-menu/