I’ve just done something like this and it’s fairly simple
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
//check if user is logged in, and add user name to menu
if (is_user_logged_in()){
$user = wp_get_current_user();
$items .= '<li>' . $user->display_name . '</li>';
}
//add login/logout link to menu
$items .= '<li>'. wp_loginout(get_permalink(),false) .'</li>';
return $items;
}
Related Posts:
- Change the Author Slug from Username to Nickname
- get_user_meta() doesn’t include user email?
- How can 2 blogs share the same users
- Different back-end language for different users?
- Migrating WordPress users into Disqus
- How to display the status of users (online – offline) in archive.php
- Remove email verification when new user register
- How to change user`s avatar?
- How to display custom user meta from registration in backend?
- Grouping users under parent user
- Check if specific username is logged in
- How to update user role without logout
- How to create a public profile for authors/contributors/users?
- How to insert new values to WordPress user Firstname and Surname Fields via DB
- How we can get the user id by its display_name
- WP_User_Query with combined meta query – not working?
- How to change WordPress user ID?
- How to assign an additional/extra/second user-role to multiple users (of a specific user-role)
- Can I hook into the invite user process to verify their email address is from a certain domain?
- wp_insert_user is not working for me?
- How to customize wp_signon()
- Is it possible to get a user with just the password field?
- Is there any way to access Ultimate Member’s custom fields?
- How to add country drop down menu to the user profile?
- New user notification doesn’t include activation link
- Use phpbb user database for WordPress
- User ability to favorite or ‘like’ content
- Users roles, make a page belonging to multiple users
- Add custom fields to the user profile
- Undeleting a deleted user
- A way to count logged in users and display count?
- stop login if user_status equal zero
- Disable user profile editing for one user
- Is it possible to get the currently logged in admin’s IP?
- Rule to redirect non logged in User to Custom Registration/login Page in .htaccess file
- How do i make my wordpress website private?
- Sort users by userID by default on users.php
- How to delete user on logout and when session expires?
- Remove Capabilities from WP admin for specific user role
- wordpress user roles are not working
- What is proper way to store info such as user marking a post as favorite? In post meta or user meta?
- What are some best practices for user exit strategy?
- Is there a way to identify a user in a custom REST API method? [duplicate]
- WP_User_Query – searching multiple fields
- wordpress disable login for unverified user
- Problem with automatic role change through cron job
- Profile page for user roles
- Search Function on a plugin WordPress User
- Replace Gravatar with UserPhoto in All Users Coulmn view
- Calling User Nickname
- How redirect after registration?
- Print profile details as PDF or from modal window
- create new users in db starting at what ID?
- About WordPress capabilities [closed]
- No more administrator roles / permissions after WordPress upgrade
- How to display text if profile fields are not filled?
- Load user by specific role
- Order users by user role
- Get user by meta key – WP multi site
- Force users to use password with specifications
- Change user slug in Buddypress
- Creating a user from a different website
- Give users alternative/second avatar that is rectangle sized
- New User Save Filter
- Followers for WordPress [duplicate]
- Cannot Modify Header Info Error on updating User Profile
- Is there a way to rate users instead of posts?
- Is it possible to build social networking website using WordPress?
- Easiest way to create an user across several websites
- Is there a way to call via javascript if a user is logged-in on a static html file?
- I need a link that directs the user that is logged to his profile
- Is this a hack? WordPress Usernames of every website we have changed into one single name automatically?
- Getting user data via ajax
- How to change default username field after login
- The same session information for peer users on two different WordPress servers
- Post Taxonomy Value get from User Field Value
- Iterating users while user iteration is suppressed
- Custom User Page
- In admin manage users page, how can I stop users with certain privileges from editing users with other privileges?
- Browser extension to allow users to submit posts front end
- Changing the admin User Profile page
- user and usermeta table not found
- UserMeta Changes Meta Value for Post ID
- Users set passwords but cannot login
- Subscriber role – blank page
- Set user role on registration so can upload file to own media library area
- Ordering list of users by last name and then by first name
- Separate Profiles for Users
- User “none” role
- Migrating Users along with their password
- show count author post today
- Limit user access to installing/configuring a plugin?
- How to get current user ID in array meta_value?
- Increase by one the user counter on specific role
- How can I list users by date in an array in meta_value?
- Email Subscribe for Downloads in WordPress
- Cant edit profile from frontend
- Wordpres password as plain text in email
- Can I provide a user’s user_ID to them and can it also be searchable in a member’s directory
- application password is missing