Born and raised in Whitney, Texas, Shafer's musical career began in his hometown of Whitney where he played in a school band. In the following years he toured the U.S., performing with, among others, the then-unknown Willie Nelson. In 1967 Shafer moved to Nashville, Tennessee, where he signed with the Blue Crest Music Publishing Company. There he wrote two songs for George Jones, "Between My House and Home" and "I'm a New Man in Town", along with many other tunes for lesser-known acts. Shafer signed contracts with Musicor and RCA as a singer, but he was never as successful as he was as a songwriter.
In the early 1970s Shafer signed an exclusive contract with Acuff-Rose Music. In the following years he wrote many songs which went on to become successful on the U.S. country charts, including several No. 1's. His songs included "The Baptism of Jesse Taylor" for Johnny Russell, "Tell Me Lying Eyes Are Wrong" for George Jones, and a series of hits for Moe Bandy. He had a longstanding friendship with Lefty Frizzell, whom he had met at his record label. He and Frizzell wrote the song "That's the Way Love Goes" together, a hit for Johnny Rodriguez and also Merle Haggard in 1983; they also wrote "I Never Go Around Mirrors" (which Frizzell recorded in 1973 and turned into a top 25 country hit a year later) and "Bandy the Rodeo Clown" for Moe Bandy, which became a major hit shortly after Frizzell's 1975 death. After Frizzell's death Shafer wrote the tribute song "Lefty's Gone" recorded by George Strait for his Something Special album.
Three divorces helped him with his song writing in the 1980s when Shafer wrote "Does Fort Worth Ever Cross Your Mind" (1985; with Darlene Shafer) and "All My Ex's Live in Texas" (1987; with his fourth wife Lyndia J.). Both of these were No. 1 hits for George Strait, and both were nominated for CMA's Song of the Year. "All My Ex's Live in Texas" was also nominated for a Grammy Award, for Best Country Song (lost to: Paul Overstreet & Don Schlitz for "Forever and Ever, Amen").
In the middle of the 1980s Shafer released two albums, I Never Go Around Mirrors and So Good for So Long, containing his greatest hits. In 1989 Keith Whitley chose the Shafer penned, "I Wonder Do You Think of Me", as the title track and the first single released after Whitley's death and went to No. 1. Also in 1989 Shafer was inducted into the Nashville Songwriters Hall of Fame.
In the 1990s and 2000s, Shafer continued to write for musicians such as John Michael Montgomery, Lee Ann Womack, and Kenny Chesney. In 2004, Shafer's recording of "All My Ex's Live In Texas" appeared on the soundtrack to the video game Grand Theft Auto: San Andreas.