Shangguan Wan'er's grandfather Shangguan Yi had become a prominent official early in the reign of and had become in 662. In 664, Emperor Gaozong was angry at the level of influence that his second wife was exerting over policies, and he consulted Shangguan Yi, who recommended that he depose Empress Wu. However, when Empress Wu discovered this, Emperor Gaozong changed his mind and instead blamed Shangguan Yi. At Empress Wu's instigation, her allies, the chancellor Xu Jingzong falsely accused Shangguan Yi of plotting with Emperor Gaozong's son Li Zhong, on whose staff Shangguan had served at one time, as well as the eunuch Wang Fusheng against Emperor Gaozong. Li Zhong was forced to commit suicide, while Wang, Shangguan Yi, and Shangguan Wan'er's father Shangguan Tingzhi were put to death.
After Shangguan Yi's and Shangguan Tingzhi's deaths, Shangguan Wan'er and her mother Lady Zheng -- a sister of the official Zheng Xiuyuan -- were spared but became slaves in the inner imperial palace. As Shangguan Wan'er grew older, learned to read and write from her mother, and she read extensively and showed talent for writing prose and poetry at an early age, as well as in matters of civil service regulations. After Empress Wu stumbled upon poems written by the 13-year-old Shangguan Wan'er in the crown prince's study, Empress Wu summoned Shangguan Wan'er and asked her to compose an essay based on a given theme right on the spot. Shangguan Wan'er performed marvellously, and the Empress was so impressed that she appointed Wan'er her personal secretary.
As Wu Zetian's secretary
Later, after Emperor Gaozong's death in 683, Empress Wu became empress dowager and deposed, in succession, her two sons, and . In 690, she took the title of "emperor" herself, abolishing Tang Dynasty and establishing her own Zhou Dynasty. Particularly after the era ''Wansuitongtian'' Shangguan Wan'er, as Wu Zetian's secretary, was in charge of drafting imperial edicts, and her writing style was said to be exceedingly beautiful. On one occasion, she was supposed to be put to death after disobeying Wu Zetian's order; Wu Zetian, caring for her because of her talent, spared her, but tattooed her face. Thereafter, Wu Zetian usually consulted with her on the officials' petitions and important affairs of state.
As imperial consort
In 705, a coup led by Zhang Jianzhi, Cui Xuanwei, Jing Hui, Huan Yanfan, and Yuan Shuji removed Wu Zetian and returned Emperor Zhongzong to the throne. At that time, Shangguan Wan'er became an imperial consort, as a concubine of Emperor Zhongzong, carrying the rank of ''Jieyu'' , the 14th rank for an imperial consort. Emperor Zhongzong put her in charge of drafting edicts and other imperial orders. She carried on an affair with Emperor Zhongzong's cousin and Wu Zetian's nephew Wu Sansi the Prince of Liang, however, and through her, Wu Sansi became a trusted advisor of Emperor Zhongzong and a lover of Emperor Zhongzong's wife as well. Subsequently, at her suggestion, Empress Wei submitted formal proposals to Emperor Zhongzong to require the people to observe three-year mourning periods for their mothers who had been divorced by their fathers and reducing the period where a man was considered an adult male from the ages to 20 to 59, to the ages of 22 to 58, in order to try to gain the people's gratitude. Emperor Zhongzong approved the proposals.
Meanwhile, in addition to Empress Wei and Consort Shangguan, Empress Wei's daughter the Princess Anle became very powerful as well, as she was Emperor Zhongzong's favorite daughter, and she had married Wu Sansi's son Wu Chongxun . She often humiliated her brother Li Chongjun the Crown Prince on account that Li Chongjun was not born of Empress Wei, at times calling him "slave." She also often suggested to Emperor Zhongzong that he depose Li Chongjun and make her crown princess. In summer 707, Li Chongjun's anger erupted, and he, along with the ethnically Mohe general Li Duozuo and Emperor Zhongzong's cousin Li Qianli the Prince of Cheng, rose in rebellion, first killing Wu Sansi and Wu Chongxun. He then attacked the palace, seeking to arrest Consort Shangguan. Consort Shangguan, Empress Wei, Li Guo'er, and Emperor Zhongzong were protected by the imperial guards, and when Li Chongjun hesitated at what to do next, his forces collapsed, and he and his cohorts were killed.
Meanwhile, Consort Shangguan's nephew Wang Yu had been warning her, through her mother Lady Zheng, that her continued behavior in working with the Wus and Empress Wei would eventually bring disaster on her and her clan. Consort Shangguan initially took no heed, but after Li Chongjun had demanded, by name, to arrest her during the 707 coup attempt, she became fearful, and she began to distance herself from Li Guo'er and Empress Wei, aligning herself more with Emperor Zhongzong's sister Princess Taiping. Despite this, she and her mother Lady Zheng, along with Li Guo'er, Empress Wei, the senior Ladies Chai and Helou, the sorceress Diwu Ying'er , and Lady Zhao of Longxi, were described as powerful and corrupt women at court, selling governmental offices at will. Consort Shangguan and the other imperial consorts were also said to, against regulations, establish mansions outside the palace.
In 708, Emperor Zhongzong established an imperial academy, with four imperial scholars, eight assistant scholars, and 12 associate scholars, selecting officials with literary talent to serve as the imperial scholars. He often held feasts that would also serve as literary competitions, and he had Consort Shangguan serve as the judge at these competitions. Late in the year, he promoted her to the rank of ''Zhaorong'', the sixth rank among imperial consorts. In addition to writing poems in her own name, she was also said to have written poems in the names of Emperor Zhongzong, Empress Wei, Li Guo'er, and Li Guo'er's sister Princess Changning. The poems were said to be beautiful and often recited by people who heard them.
By spring 709, Consort Shangguan was having an affair with the official Cui Shi, and on account of that relationship, she recommended him to be a chancellor. Emperor Zhongzong agreed. By summer, however, Cui and another chancellor, Zheng Yin, were charged with corruption. As a result, Cui was set to be exiled to be the military advisor to the prefect of Jiang Prefecture . However, Consort Shangguan, Li Guo'er, and Li Guo'er's new husband Wu Yanxiu then spoke on his behalf secretly, and Emperor Zhongzong instead made Cui the prefect of Xiang Prefecture .
In fall 710, Emperor Zhongzong died suddenly -- a death that traditional historians assert to be a poisoning carried out by Empress Wei and Li Guo'er, to allow Empress Wei to seize power and eventually take the throne and Li Guo'er to become crown princess. In the aftermath of Emperor Zhongzong's death, Empress Wei, who initially kept the death secret, tried to consolidate power, while Consort Shangguan and Princess Taiping were consulting each other in posthumously drafting a will for Emperor Zhongzong. Under their plan, Emperor Zhongzong's youngest son the Prince of Wen would inherit the throne; Empress Wei would serve as empress dowager and regent, assisted by Li Dan the Prince of Xiang . Once the will was promulgated, however, two chancellors closely aligned with Empress Wei -- her cousin Wei Wen and Zong Chuke -- objected and ordered the will revised, and Empress Dowager Wei became sole regent for Li Chongmao , without participation by Li Dan in the regency.
Meanwhile, Zong, Wu Yanxiu, and other officials Zhao Lüwen and Ye Jingneng , were advocating to Empress Dowager Wei that she take the throne. They also believed that Li Dan and Princess Taiping were in the way and should be removed. The official Cui Riyong leaked their plans to Li Dan's son the Prince of Linzi, and Li Longji quickly formed a plan with Princess Taiping and her son Xue Chongjian to act first. Less than a month after Emperor Zhongzong's death, they launched a coup, quickly killing Empress Wei, Li Guo'er, and Empress Wei's clan members. When Li Longji's soldiers, commanded by his associate Liu Youqiu, reached the pavilion where Consort Shangguan lived, Consort Shangguan came out of the pavilion to greet Liu and Li Longji, presenting to them the original will of Emperor Zhongzong that she had drafted, seeking to be spared. Li Longji refused to spare her, however, and she was dragged out and beheaded.
Soon, under the suggestion by Princess Taiping, Li Longji, and Li Longji's brother Li Chengqi the Prince of Song, Emperor Shang was removed from the throne, and Li Dan took the throne again. In 711, he restored Consort Shangguan's title as ''Zhaorong'', and gave her the posthumous name of Wenhui . Sometime after Emperor Ruizong in turn yielded the throne to Li Longji , Emperor Xuanzong ordered that Consort Shangguan's works be collected into a 20-volume collection, and he had the chancellor Zhang Yue write the preface to the collection.