-1

I have a page called edit profile, i have installed the profile builder plugin,so the users can edit their profile from front end, if the user is logged in i want to show the edit profile and logout else it is login. how can i achieve that? i am using wp-bootstrap responsive theme, i am new in wordpress development any one please help me.Do i need to change any thing in the header.php file?

2

You can get the current user's info by using wp_get_current_user() and then get the profile edit link by using the user's ID as following:

 function wpse_125929_login_logout( $items ) {
    if ( is_user_logged_in() ) {
        $current_user = wp_get_current_user();
        $profile_edit_url = admin_url( 'user-edit.php?user_id=' . $current_user->ID );
        $profile_link = '<li><a href="' . $profile_edit_url . '">Edit Profile</a></li>';
        $logout_url = '<li><a href="'. wp_logout_url() .'">Logout</a></li>';
        $items = $items. $profile_link. $logout_url;   
    } else {
        $login_link = '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
        $items = $items. $login_link;
    }  
    return $items;
}
add_filter( 'wp_nav_menu_items', 'wpse_125929_login_logout' );
  • i am using wp-bootsstrap theme, i a default menu, how i can add the edit profile, logout links to the menu? – Naveen Dec 10 '13 at 10:46
  • 1
    @Naveen I have modified the answer. Now it will append the edit profile link as well as the logout link to the primary menu for logged in user otherwise Login link for guest user. – Sabita Sahoo Dec 10 '13 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.