McDonald’s has stopped allowing customers to use their restaurants’ free Wi-Fi to view porn.

The world’s largest restaurant company made the move after an internet safety advocacy group pressured it for two years to block the X-rated stuff.

McDonald’s now joins Panera Bread, Subway and Chick-fil-A as chains that block customers from using free Wi-Fi to view porn, the group, Enough Is Enough, told The Post.

“We discovered that corporate America is not aware of how some people use their free Wi-Fi,” said Donna Rice Hughes, the group’s chief executive.

Enough Is Enough, launched in 1994, has played a key role in the passage of internet safety legislation, according to its website.

It hasn’t had success with every arena, however. Starbucks, for example, does not filter its free Wi-Fi, Rice Hughes said.

“I’ve asked Starbucks employees whether they’ve had problems with customers in stores watching porn, and they’ve said, yes, that they sometimes have to tap customers on the shoulder” to close a website, she said.

Enough Is Enough’s campaign includes ending free Wi-Fi access to pornography in public places like shopping malls, restaurants, stadiums, hotel lobbies and airplanes.

Rice Hughes is not a stranger to the public spotlight. In 1988, the former beauty pageant winner’s suspected affair with Democratic presidential candidate Sen. Gary Hart ended his White House campaign.

In August, at the height of Subway pitchman Jared Fogle’s child pornography scandal, Rice Hughes sent a letter to the chain’s president, Suzanne Greco, advising her to counter the bad press by blocking access to porn via its stores’ free Wi-Fi.

“Through your current unfiltered internet access, Subway is allowing patrons to view illegal child pornography and even seek opportunities to sexually exploit children or teens,” she wrote. “None of these scenarios match the family-friendly environment that you have worked so hard to create.”

Subway did not respond to the group’s letter.

However, on Wednesday, Subway, in an email to The Post, said its restaurants with Wi-Fi do filter “non-family-friendly content.”

Rice Hughes made a similar plea to Starbucks after the Seattle chain implemented a Wi-Fi filter in its UK stores.

Starbucks has yet to reply to the group — or to a call from The Post on Wednesday.

New York City had run into similar problems with teenagers accessing porn via its 180 free Wi-Fi hotspots, The Post has reported. The city’s vendor, LinkNYC, has since added a porn filter.

Rice Hughes, who started her group’s porn-free Wi-Fi campaign two years ago, said she has met with execs from Google, Comcast, AT&T and others to provide “a value-added service for their corporate customers” similar to what AT&T was able to do for McDonald’s.