WASHINGTON — Before it became the chief sticking point in a government shutdown drama that threatens to consume his presidency at a critical moment, President Trump’s promise to build a wall on the southwestern border was a memory trick for an undisciplined candidate.

As Mr. Trump began exploring a presidential run in 2014, his political advisers landed on the idea of a border wall as a mnemonic device of sorts, a way to make sure their candidate — who hated reading from a script but loved boasting about himself and his talents as a builder — would remember to talk about getting tough on immigration, which was to be a signature issue in his nascent campaign.

“How do we get him to continue to talk about immigration?” Sam Nunberg, one of Mr. Trump’s early political advisers, recalled telling Roger J. Stone Jr., another adviser. “We’re going to get him to talk about he’s going to build a wall.”

Talk Mr. Trump did, and the line drew rapturous cheers from conservative audiences, thrilling the candidate and soon becoming a staple of campaign speeches. Chants of “Build the wall!” echoed through arenas throughout the country.