0

Am creating a WordPress site whereby am enabling users to upload their own custom avatars using a Plugin called One user Avatar.

The upload functionality is working fine

I want the image to be shown as an avatar when a user logs in. This should appear in the top-right corner. Since my menus are created dynamically using Wp Custom Navwalker. Am using a filter called wp_nav_menu_objects to filter the menu of a logged in user and add the avatar beside the username eg Welcome [avatar image] John Doe ,

The problem is that instead of the avatar showing, what shows is the code . Below is the filter hook am using:

//Filter inside functions.php
function my_dynamic_menu_items( $menu_items ) {

    foreach ( $menu_items as $menu_item ) {
        if ( strpos($menu_item->title, 'Welcome') !== false) {
        $menu_item->title =  'Welcome' . ' ' . get_wp_user_avatar( get_the_author_meta( 'ID' ), 'medium' );
        }
    }
    return $menu_items;
}
add_filter( 'wp_nav_menu_objects', 'my_dynamic_menu_items', 10 );

This is the output on the frontend

enter image description here

Pweb
  • 155
  • 1
  • 4
  • 18

0 Answers0