Created
June 12, 2022 09:11
-
-
Save daddiofaddio/2fd2600b2e42d7709750ee6eb20212ed to your computer and use it in GitHub Desktop.
Add avatar & username as menu item to WP menu (functions.php)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ADD AVATAR/USER MENU ITEM */ | |
add_filter( 'wp_nav_menu_objects', 'my_dynamic_menu_items', 10 ); | |
function my_dynamic_menu_items( $menu_items ) { | |
foreach ( $menu_items as $menu_item ) { | |
if ( strpos($menu_item->title, '#profile_name#') !== false) { | |
$menu_item->title = str_replace("#profile_name#", wp_get_current_user()->user_login .' '. get_avatar( wp_get_current_user()->user_email, 50), $menu_item->title); | |
} | |
} | |
return $menu_items; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment