WASHINGTON — After failing to deliver on their years-long promise to repeal the Affordable Care Act and faced with the sudden popularity of Obamacare’s consumer protections, GOP candidates across the country are struggling for the first time in a decade to put together a cohesive message on healthcare.

Die-hards still want to repeal the 2010 law, the issue that propelled them to majorities in the House and Senate, but a growing number of Republicans — particularly those facing tough elections — want to quietly admit defeat and move on.

“Even to bring it up is picking at the scab,” said Joe Antos, a health policy expert at the American Enterprise Institute, a conservative think tank. “It’s reminding people that they [failed]. The base isn’t that stupid.”

Other GOP candidates find themselves trying to thread an awkward needle of opposing Obamacare — a law that is still unpopular with core Republican voters — while supporting some of its key provisions. A few Republicans who once called for the repeal of Obamacare are now even embracing it, albeit cautiously.

All that makes for a starkly different climate than just two years ago, when GOP candidates could count on opposition to Obamacare as a guaranteed applause line on the stump.

Once repeal became an actual possibility, the Affordable Care Act — particularly a few individual pieces — became more popular with the public. Forty-eight percent of adults have favorable opinions of the law while 40% have unfavorable views, according to a recent poll by the nonpartisan Kaiser Family Foundation. In April 2016, those were flipped: 49% of adults with unfavorable opinions and 38% favorable.

Some Republicans in competitive districts have shifted to match the change in public opinion. For example, Rep. David Joyce (R-Ohio), who is seeking reelection in a district that leans Republican, is running ads boasting that he opposed his party’s attempt to eliminate protections for people with preexisting conditions.

But between 2013 and 2016, Joyce cast dozens of votes to repeal or undermine the health law. Back then, when President Obama was able to veto repeal efforts, Republicans were able to vote against Obamacare with no threat of their constituents losing coverage. After Donald Trump was elected and Republicans tried to repeal the law, Joyce changed his position.

Republican candidates for governor in Ohio and Nevada, both once-harsh critics of Obamacare, now say they won’t — if elected — undo previous decisions to expand Medicaid in their states through the 2010 law.

Meanwhile, Democrats — once the party that struggled over healthcare in part because of Obamacare’s rocky rollout — are hammering GOP candidates on the issue, blaming Republican candidates for rising drug prices and premium instability, and trying to take away well-liked protections such as the ban on denials over preexisting conditions.

“Even in places where candidates didn’t want to say ‘Obamacare’ four years ago, we have candidates running on Medicaid expansion,” said Jared Leopold, spokesman for the Democratic Governors Assn.

Richard Cordray, the Democratic candidate for Ohio governor, has tried to make healthcare a key issue in his bid against Republican Mike DeWine, the state’s attorney general, accusing DeWine of trying to end the Medicaid expansion and eliminate coverage for 700,000 Ohioans.

But even as DeWine assures voters he won’t undo expansion, he also tried to put a conservative stamp on it by promising reforms. Echoing other Republican governor hopefuls, DeWine wants to consider adding work requirements to Medicaid — an idea that the Trump administration has backed but that is being challenged in court.

Republican candidates for the U.S. Senate have also shifted ground in some cases. State Attys. Gen. Patrick Morrisey of West Virginia and Josh Hawley of Missouri joined a multistate, GOP-backed lawsuit that seeks to end a requirement in the 2010 law that all Americans have insurance. It was a move that helped buoy their conservative bona fides.

But now as they run for the Senate, they have had to distance themselves somewhat from the effort, particularly after the Trump administration adopted the legal position that not only should the individual mandate go but preexisting conditions protections should too.

The preexisting conditions provision is by far the most popular part of Obamacare. Both GOP candidates now say they support requiring insurance companies to cover people with preexisting conditions, even as they remain part of the repeal lawsuit.

Some Republicans are still eager to keep trying to repeal or dismantle the law.

Sen. Ted Cruz (R-Texas), who is facing a surprisingly strong challenge from Rep. Beto O’Rouke (D-Texas), wants the GOP to try Obamacare repeal again. Earlier this month, he went to the Senate floor to try to block the District of Columbia from requiring people to have health insurance — a requirement similar to the Obamacare rule the GOP repealed across the country earlier this year.

The GOP candidate for governor in Maine has pledged to continue incumbent Gov. Paul LePage’s opposition to expanding Medicaid under Obamacare — an expansion that 59% of Maine voters approved in a ballot measure last year. Minnesota’s GOP gubernatorial candidate won his primary by promising to move the state away from its Obamacare insurance exchange but offered few specifics on his alternative.

And GOP Senate challengers Leah Vukmir in Wisconsin and Marsha Blackburn in Tennessee won their primaries in part by pledging to do more to repeal the law.

The result is that even if Republicans do maintain control of both chambers of Congress — seemingly a long shot — any legislative effort to stabilize the health law’s insurance markets is likely to be met with opposition from the conservative end of the Republican party.

Healthcare “is an extremely hard thing for Republicans to agree on,” said GOP strategist Doug Heye, adding that the party is divided among those who want repeal Obamacare, those who want to move on and those seeking a middle ground. “When you have three different strains of thought, how do you talk about it?”

Moderate Democrats are more than happy to exploit the GOP fissures. Sens. Heidi Heitkamp of North Dakota and Joe Manchin of West Virginia both started running ads touting the preexisting condition protections and attacking their opponents for trying to get rid of them.

Sen. Joe Donnelly (D-Ind.), who faces an uphill battle toward reelection, has taken a similar tack against his opponent, Mike Braun, who has backed repeal of Obamacare.

“Mike Braun says he’s for preexisting conditions coverage,” one Donnelly video says. “There’s only one problem. Mike has said time after time after time he’s against it.”

jennifer.haberkorn@latimes.com

Twitter: @jenhab