[Warning: Mild spoilers for “Doctor Sleep” ahead.]

The filmmakers behind Warner Bros.’ “Doctor Sleep” — based on Stephen King’s 2013 follow-up novel to “The Shining” — knew they had big shoes to fill, so they got creative in paying homage to the original book and 1980s movie.

Though the sequel is set decades after the first film, “Doctor Sleep” features an appearance by Danny Lloyd, the actor best known for playing young Danny Torrance in “The Shining.” Lloyd’s cameo marks the now 47-year-old’s first professional acting gig since he starred in the horror classic at age 6. Lloyd has largely stayed out of the spotlight since then, save for an appearance in the 1982 TV movie “Will: The Autobiography of G. Gordon Liddy.”

“[Lloyd] was excited to do [the cameo]. He hadn’t acted since [the original],” producer Trevor Macy told Variety on the red carpet at Tuesday night’s premiere at Regency Village Theatre in Westwood. “He’s a schoolteacher, and a very successful one at that, like making the world better. He came back for a day, and we were thrilled to have him.”

So how did executives convince the former child star to make an appearance? Behold the power of social media.

“[Director] Mike [Flanagan] found him and direct-messaged him on Twitter,” Macy said.

Although Lloyd briefly pops up on-screen, he’s not reprising his original role. Ewan McGregor portrays the adult Danny Torrance in “Doctor Sleep.”

“At the beginning of the film, Danny is at rock bottom, he’s an alcoholic,” McGregor told Variety. “He’s living on a Greyhound bus, drifting across America, doing little jobs where he can find them. He’s drinking, so as not to experience his very real demons that still visit him from the Overlook Hotel and the abuse he survived at the hands from his alcoholic father. But, he’s an alcoholic himself.”

As with anything related to “The Shining,” Jack Nicholson’s legacy shone brightly over Tuesday’s premiere. Nicholson doesn’t appear in “Doctor Sleep,” but his role as Jack Torrance is synonymous with the first movie’s indelible imagery and revered status. “It was an iconic performance,” McGregor acknowledged.

While Lloyd was coaxed out of retirement for a cameo, Nicholson did not return for “Doctor Sleep.”

“With Jack, I knew that they approached him for ‘Ready Player One,’ and that he seems to be very serious about being retired,” Flanagan told Variety. “I had known that he was supportive [of the sequel] but retired.”

Since (spoiler alert!), Nicholson’s character freezes to death in “The Shining,” Flanagan admits it would have been difficult for him to appear in the follow-up.

“I didn’t know how that would really work,” Flanagan said. “Even if he were to come back, if he were appearing as a different character, I thought that would set people’s hair on fire. … He was absolutely a presence on set, though, whether he knew it or not.”

“Doctor Sleep” is in theaters on Nov. 8.