Conjugated polymers are promising light harvesters for water reduction/oxidation due to their simple synthesis and adjustable bandgap. Herein, both cyanamide and triazole functional groups are first incorporated into a heptazine‐based carbon nitride (CN) polymer, resulting in a mesoporous conjugated cyanamide‐triazole‐heptazine polymer (CTHP) with different compositions by increasing the quantity of cyanamide/triazole units in the CN backbone. Varying the compositions of CTHP modulates its electronic structures, mesoporous morphologies, and redox energies, resulting in a significantly improved photocatalytic performance for both H2 and O2 evolution under visible light irradiation. A remarkable H2 evolution rate of 12723 µmol h−1 g−1 is observed, resulting in a high apparent quantum yield of 11.97% at 400 nm. In parallel, the optimized photocatalyst also exhibits an O2 evolution rate of 221 µmol h−1 g−1, 9.6 times higher than the CN counterpart, with the value being the highest among the reported CN‐based bifunctional photocatalysts. This work provides an efficient molecular engineering approach for the rational design of functional polymeric photocatalysts.