A photo of US President Donald Trump smiling broadly and raising his thumb as his wife Melania embraced a baby lost his parents in a random shooting in El Paso, Texas became the subject of social media talk after Melania posted the photo on Twitter.

The photo was taken on Wednesday at the University of El Paso Medical Center during Trump's visit to the western Texas border town with paramedics, doctors and people who survived Saturday's crime at a Wal-Mart store.

Earlier that day, the president and his wife traveled to Dayton, Ohio, on a similar visit to a hospital for sympathy following a bloody indiscriminate shooting just 13 hours after El Paso.

Together, they killed 32 people, including the Dayton massacre gunman.

Trump avoided the press during his visits to the hospitals, which the media were not allowed to cover, but the White House later aired a short video of the visits.

The first lady also posted several pictures on Twitter of the visit, including one in front of a slogan for the University of El Paso Medical Center with a two-month-old baby whose parents were killed in the Wal-Mart attack while reportedly protecting him from bullets.

Trump stood next to the first lady smiling and raising his thumb. The aunt and uncle of the child, who was also smiling, stood on both sides and put his arm on Trump's shoulder as the four stood to take the picture.

Many on social media saw the picture as a demonstration of the president's lack of sympathy or respect for the occasion.

"A child was taken from his home and forced to become a support in the form of a memorial to the same monster whose hatred killed his parents," Democratic Party member Greg Benillo said on Twitter.

The boy's uncle, who described himself and his dead brother as supporters of Trump, told The Washington Post in an interview published on Friday that the visit of President Waste and denied that Trump was there "to achieve any kind of political propaganda."

He said he chose to take his orphan's nephew to the hospital to meet Trump, adding that others would forget the tragedy of his family. The child broke two fingers during the shooting, but doctors later allowed him to be discharged from hospital.