The sensitive determination of penicillin G (PG) in complex environments is essential for guaranteeing food safety and human health. Herein, a new dual-modal electrochemical (EC)–photoelectrochemical (PEC) aptasensing strategy has been proposed based on an Fe-doped covalent triazine framework (denoted as Fe-MA-Dha-CTF) synthesized by using 2,5-dihydroxyterephthalaldehyde (Dha) and melamine (MA) as building blocks and utilized to detect trace PG. Compared with the platform based on metal-free MA-Dha-CTF, the constructed Fe-MA-Dha-CTF demonstrated enhanced photoelectric conversion efficiency, superior electrochemical activity, and high bioaffinity toward the PG-targeted aptamer. The established Fe-MA-Dha-CTF-based dual-modal EC–PEC aptasensor exhibited ultralow limits of detection of 0.08 and 0.7 fg mL−1 as deduced by using EC and PEC techniques, respectively, within a wide PG concentration range of 1 fg mL−1 to 10 ng mL−1. Moreover, the proposed EC–PEC aptasensor exhibited high selectivity, good stability, acceptable reproducibility, and great practicability in diverse real samples. The CTF-based dual-modal aptasensing approach presented here can extend the application of porous-organic frameworks in biosensing.