需要在菜单中为登录用户编辑配置文件链接wordpress


Need edit profile link in the menu for logged in users wordpress?

我有一个名为编辑配置文件的页面,我安装了配置文件生成器插件,所以用户可以从前端编辑他们的配置文件,如果用户登录了,我想在菜单中显示编辑配置文件和注销链接,否则就是登录。我怎样才能做到这一点?我正在使用wpbootstrap响应主题,我是wordpress开发的新手,任何人都请帮助我。我需要更改header.php文件中的任何内容吗?

<?php
if ( is_user_logged_in() ) {
    // i want to add Edit profile and logout to the menu
} else {
    // i want to add login to the menu
} ?>

您可以使用wp_nav_menu_items过滤器添加菜单

add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 10, 2 );
function your_custom_menu_item ( $items, $args ) {
if ( is_user_logged_in() ) {
    $items .= '<a href="user profile link">Show whatever</a>';
} else {
     $items .= '<a href="login link">Show whatever</a>';
}
    return $items; /* This will have the menu items */
}

参考