 His family claimed ancestry from the early Han Dynasty general Zhang Er (張耳).The traceable ancestry of Zhang Wenwei's included officials of Sui Dynasty and Tang Dynasty.His grandfather Zhang Junqing (張君卿) was a copyeditor at Jixian Pavilion (集賢院), and his father Zhang Shang (張裼) served in a number of prominent positions, including, eventually, the military governorship ("Jiedushi") of Tianping Circuit (天平, headquartered in modern Tai'an, Shandong).