Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daddiofaddio/2fd2600b2e42d7709750ee6eb20212ed to your computer and use it in GitHub Desktop.
Save daddiofaddio/2fd2600b2e42d7709750ee6eb20212ed to your computer and use it in GitHub Desktop.
Add avatar & username as menu item to WP menu (functions.php)
/* 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