ZnFe2O4 and MxZn1-xFe2O4 (M = Sn, Mg) nanorods are synthesized by a facile co-precipitation method followed by thermal treatment of metal-organic frameworks in air to form mesoporous structure. Temperatures of thermal treatment affects the porous structure of the materials and influences charge/discharge process of ZnFe2O4. From the electrochemical performance, we find that doping Sn which is electrochemically active would raise the voltage plateau corresponding to the reaction peaks of the doping elements, and Sn0.05Zn0.95Fe2O4 exhibits the highest capacity of 1318 mA h g−1 after 50 cycles at 0.1 C. In contrast, doping Mg which is electrochemically inactive would inhibit volume change and stabilize structure during lithiation-delithiation. Mg0.9Zn0.1Fe2O4 shows an excellent reversible capacity of 811 mA h g−1 with a capacity retention of 82% after 250 cycles at 1 C, while the pristine ZnFe2O4 only remains 382 mA h g−1 with a capacity retention of 32%.