Wei Xuantong was born in 617, near the end of Tang Dynasty's predecessor Sui Dynasty. He was from what would eventually become Ding Prefecture, and his grandfather Wei Shikuo had served as a general for Northern Qi.
During Emperor Gaozong's reign
Wei Xuantong himself had passed the imperial examination, and thereafter became the magistrate of Chang'an County, one of the two counties making up Tang's capital Chang'an. By 664, he was serving as the director of performance reviews at the ministry of civil service, when, on account of his friendship with the chancellor Shangguan Yi, who had been executed after unsuccessfully trying to persuade Emperor Gaozong to depose his powerful wife Empress Wu, Wei was exiled to the Lingnan region. It was said that during his exile, he was not particularly interested in returning to politics, and he spent most of his days hunting. Early in Emperor Gaozong's Shangyuan era, there was a general pardon, and Wei was recalled to the capital. Liu Shenli the minister of public works was aware of Wei's talent, and he recommended Wei. Wei was subsequently made the secretary general of Qi Prefecture, and then the deputy minister of civil service. In 682, he was given the designation Tong Zhongshu Menxia Pingzhangshi, making him a chancellor de facto. He was also created the Baron of Julu. Around this time, Wei also submitted a lengthy petition to Emperor Gaozong, advocating a major reform of the civil service system. In his petition, he pointed out that during the Zhou Dynasty and Han Dynasty, the responsibilities for recommending, promoting, and evaluating officials were split between various central government officials and local officials, and that only during Cao Wei and Jin Dynasty did the responsibilities began to be concentrated in a single ministry of civil service—a system that he found faulty in that it required a small number of officials to make snap judgment as to the merits of the officials for the entire state, and therefore, even if the officials were capable and honest, they would not be able to make correct decisions all the time—and that the system was open to manipulation through corruption or incompetence. Emperor Gaozong did not take action on his petition. It was also around this time that Wei would bring an enmity against him that would eventually be his undoing. At this time, Zhou Xing, the magistrate of Heyang County, had become known for his abilities, and was summoned to the capital, as Emperor Gaozong was considering promoting him. However, someone submitted a letter to Emperor Gaozong, pointing out that Zhou had not passed imperial examinations, and Emperor Gaozong changed his idea about promoting Zhou. However, Zhou was not aware of this, and he repeatedly visited the government officials, awaiting a promotion. The chancellors said nothing to him, but eventually Wei told him, "Magistrate Zhou, you may go." Zhou thereafter believed that Wei was the one who blocked his promotion, and hated Wei immensely.
During Empress Dowager Wu's regency
In 683, Emperor Gaozong died and was succeeded by his son Li Zhe, but in early 684, after Emperor Zhongzong displayed signs of independence, Empress Wu deposed Emperor Zhongzong and replaced him with his brother Li Dan the Prince of Yu, but thereafter held onto power even more tightly. Meanwhile, Wei Xuantong continued to serve as chancellor. By 685, he was serving as one of the secretaries general for the executive bureau of government, when he was made Luantai Shilang, the deputy head of the examination bureau, and he was given a more honored designation as chancellor de facto, Tong Fengge Luantai Sanpin. In 687, he became acting Nayan, the head of the examination bureau and a post considered one for a chancellor and made the official in charge of Chang'an. By 689, Zhou Xing had become a powerful official—as he had been in charge of many politically charged investigations carried out against officials and nobles under Empress Dowager Wu's direction. He still resented Wei for what he thought was Wei's role in blocking his promotion. Wei had been great friends with fellow chancellor Pei Yan, who was executed in 684 for what Empress Dowager Wu saw as opposition against her. Zhou, knowing this, falsely accused Wei of having said, "The empress dowager is old. It is better to support the emperor, for he will last longer." This angered Empress Dowager Wu, and she ordered that Wei commit suicide, and she sent the assistant imperial censor Fang Ji to monitor his suicide. When Fang got to Wei's mansion, he said to Wei, "Honored old man, why do you not pretend to be making a secret accusation? That way, the empress dowager will summon you to her presence, and when she does, you can explain that the accusation against you is false." Wei sighed and responded, "What is the difference between being killed by men and being killed by ghosts ? How can I be an accuser?" He later committed suicide.