SALT LAKE CITY — Governor Gary Herbert has signed a bill into law that allows county clerks to opt out of performing same-sex marriages on religious grounds, provided someone in the office is willing to.

The governor quietly signed Senate Bill 297 into law on Friday. The bill was an attempt to address religious objections over same-sex marriage, while also guaranteeing what the courts had ordered when it legalized such unions last year.

“The governor made it clear at the opening of the legislative session that anti-discrimination and religious freedom bills should be advanced together,” Herbert’s spokesman, Marty Carpenter, said in an email Friday to FOX 13. “He is proud of what Utah has done to find common ground on these issues and he feels SB297 provides protections to religious freedom that are an important part of that effort.”

SB297 requires that county clerk’s offices perform marriages and that someone be available to marry a same-sex couple. At the time the bill was introduced, Senate Majority Whip Stuart Adams, R-Layton, said his bill provided that if no one would marry a same-sex couple — then no one would marry in that county, gay or straight.

Utah gay rights groups were originally stunned by the bill and objected to its language. In subsequent versions of SB297, they declared themselves neutral over it.

“When 297 was originally drafted, it contained elements harmful to the LGBT community. These were no doubt unintended,” said Equality Utah director Troy Williams. “We are grateful that Sen. Adams heard our concerns and amended the final bill. The law affirmatively provides marriage ceremonies for same sex couples in every county in Utah. Clerks cannot pick and choose what couples they want to marry.”

The ACLU of Utah published on its website a “frequently asked questions” guide to SB297 to articulate the new law’s effect:

The bill was introduced shortly after Senate Bill 296 was unveiled, which added sexual orientation and gender identity to the list of those protected against discrimination in housing and employment. At the same time, SB296 allowed protections for people expressing religious viewpoints.

That bill was compromise legislation between gay rights groups, lawmakers and The Church of Jesus Christ of Latter-day Saints.