Replacing a specific menu item

This is relatively easily done using the walker_nav_menu_start_el filter (without all that PHP tag spam):

function nav_replace_wpse_189788($item_output, $item) {
  //   var_dump($item_output, $item);
  if ('Profile' == $item->title) {
    global $my_profile; // no idea what this does?
    if (is_user_logged_in()) { 
      return '<div class="img" data-key="profile">'.get_avatar( get_current_user_id(), 64 ).'</div>';
    }
  }
  return $item_output;
}
add_filter('walker_nav_menu_start_el','nav_replace_wpse_189788',10,2);

Note: I had to edit your code to return a string, not echo one. You may need to tweak the if conditional. Uncomment the var_dump() to see what you have to work with.

Leave a Comment