Skip to content

Instantly share code, notes, and snippets.

@kimwhite
Last active June 24, 2024 12:12
Show Gist options
  • Save kimwhite/51111f4f1da7713cc065a84d7b78cbd9 to your computer and use it in GitHub Desktop.
Save kimwhite/51111f4f1da7713cc065a84d7b78cbd9 to your computer and use it in GitHub Desktop.
<?php
/**
* This recipe will add Welcome User Display name to the Primary Menu
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_add_welcome_user_menu_item( $items, $args ) {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$name = $user->display_name; // or user_login , user_firstname, user_lastname
$items = '<li><a href="">Welcome, ' . $name . '</a></li>' . $items;
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_add_welcome_user_menu_item', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment