U.S. Senator Ted Cruz and Wisconsin Governor Scott Walker last week learned the same lesson many other Republicans have during this congressional election year: One way or the other, it is hard to escape Donald Trump.

Cruz and Walker both ran against Trump for the 2016 Republican presidential nomination, and had been campaigning for re-election largely independent of the president. But with polls showing their races tight ahead of the Nov. 6 elections, each walked onto a stage with Trump last week at separate rallies in Texas and Wisconsin.

In Wisconsin, Trump told the boisterous crowd that Walker could be “nasty” during the 2016 presidential campaign but now was a “great friend.” Earlier in the week Trump told Texans that Cruz, who he once derided as “Lyin’ Ted," was now “Beautiful Ted.”

>> From lynchings to mass shootings: The history of deadly attacks on Jews in America ■ Israel's chief rabbi refuses to call Pittsburgh massacre site a synagogue ■ Opinion: Netanyahu legitimized Trump and Orban's anti-Soros campaigns. This anti-Semitism is killing Jews in America

When election season began, many Republican candidates tried to avoid making the vote a referendum on the president, who remains unpopular with a majority of Americans. Instead, they trumpeted the strong U.S. economy and tax cuts passed by Congress last year, but those issues did not resonate with voters.

Faced with the prospect of losing control of the U.S. House of Representatives and a tough Senate battle, more Republicans have turned for help to the president despite his divisive poll numbers, to insure that his passionate supporters will turn out. The party is also adopting his blistering rhetoric on matters such as immigration and national security.

Trump plans to be a campaign trail fixture between now and Election Day, with a spate of rallies planned.

Democrats must win two seats in next week’s elections to assume control of the Senate and 23 to take the House, a more likely outcome.

Cruz remains in a close race with Democratic challenger Beto O’Rourke. On the heels of Trump’s visit, he echoed Trump's rhetoric on 2016 Democratic presidential candidate Hillary Clinton, saying at an event last week that O’Rourke should be locked up in a cell with Clinton. Cruz later said he was joking.

Walker, who has been courting independent voters during his re-election campaign, released a TV ad ahead of Trump’s arrival accusing his Democratic opponent, Tony Evers, of favoring "special treatment for illegals." Evers termed the ad "desperate."

Immigration is at the heart of Trump’s push to help Republican candidates in the election’s final days. He has frequently warned that a migrant caravan making its way to the southern border from Central America poses a security threat.

Democratic candidates say endangered Republicans are embracing Trump now because independent voters view last year’s tax bill as a boon for the wealthy and are concerned about issues such as health care.

“They don’t have any kind of consistent economic message they can run on,” said Jeb Fain, a spokesman for House Majority PAC, an advocacy group that supports Democratic candidates.

A CULTURE WAR

Last month Democratic chances of taking both the Senate and the House seemed brightest. Then Republicans, with Trump leading the way, seized on the battle over the confirmation of Supreme Court Justice Brett Kavanaugh to tag the nominee's opponents as a “liberal mob,” suggesting that the country would plunge into anarchy if Democrats took control of Congress.

The message was quickly amplified by the National Republican Congressional Committee (NRCC) and allies such as the Congressional Leadership Fund. Both groups cut ads accusing Democrats of being closet “radicals” and “socialists.”

The Congressional Leadership Fund, tied to outgoing House Speaker Paul Ryan, released a wave of radio ads this month targeting Democratic contenders in tight races in states such as Kentucky, Minnesota and Virginia, as part of the "liberal mob.”

The Democrats included Amy McGrath, a former Marine Corps pilot, Dan Feehan, who served as an Army officer in the Iraq War, and Abigail Spanberger, a former CIA officer.

Republican Senate candidates such as Marsha Blackburn in Tennessee, Mike Braun in Indiana, and Josh Hawley in Missouri last week also warned that the caravan is a threat. Blackburn called it an “illegal alien mob.”

Many Republicans say the strategic shift has boosted their chances of holding the Senate, with several races breaking their way in recent weeks.

“If Democrats take back power, their far-left mobs would hasten dysfunction and grind our economic progress to a halt,” said Matt Gorman, communications director for the NRCC.

A Republican source familiar with the party’s strategic thinking said the effort was aimed at keeping Republican voters from crossing over to Democratic candidates by appealing to their social values while taking advantage of Trump’s affinity for waging battles over culture.

Marc Lotter, a former top aide to Vice President Mike Pence, praised Trump’s “ability to identify key messages and themes, set the table, and see it play out in the electorate.”

But there is a political risk in going too far in Trump’s direction. Last year as the election approached for Virginia governor, Republican Ed Gillespie's campaign increasingly turned to warning about immigrant gangs. Suburban voters were not swayed and he lost decisively.

That is largely why a bevy of Republican House candidates from suburb-heavy districts have tried to keep their distance from the president during the campaign.

Even so, many of those moderate candidates could lose their seats to Democrats next week. In the long term, this means Republican lawmakers, whether in the majority or the minority, will be tied to Trump more closely than ever.