More companies are scouring job candidates’ online personas for racist and other red-flag comments. That hasn’t kept social-media trails from morphing into hiring minefields.

The New York Times has become the latest employer to grapple with a public furor after announcing last week it hired journalist Sarah Jeong as a technology writer for its editorial board. Soon after, tweets she had posted between 2013 and 2015 disparaging white people—in one instance, using the hashtag #cancelwhitepeople—resurfaced and a social-media outcry ensued.

Defending its hire, the Times said in a written statement that it knew about Ms. Jeong’s tweets before hiring her and that “she understands that this type of rhetoric is not acceptable at The Times.” On Twitter, Ms. Jeong said she regretted the posts, which she said had been aimed at online harassers, not a general audience.

Last month, Walt Disney Co. cut ties with “Guardians of the Galaxy” director James Gunn after years-old, inflammatory tweets of his were resurfaced. Mr. Gunn said that the comments were “wildly insensitive” and “don’t reflect the person I am today.” In recent weeks, three Major League Baseball players apologized for unearthed racist and antigay tweets written during their high-school days.

With job recruits’ social-media histories readily available, more employers are trying to head off or prepare for such controversies, especially with high-profile hires. In a 2017 survey of more than 2,300 hiring managers and human-resources executives by jobs website CareerBuilder, 70% said they screened candidates’ social-media histories—up from 60% the previous year. One-third said they had found discriminatory comments that caused them not to hire someone.