The pore structures of carbons profoundly affect their properties and functions. The hard template method has been extensively employed to fabricate porous carbons. Generally, the heteroatoms of porous carbons remarkably boost their performances, thus various of strategies have been carried out to incorporate the heteroatoms into porous carbons. The usual hard templates, such as silica nanoparticle and polystyrene sphere, only function as a pore‐forming agent. Herein, nanoscale melamine resin spheres (NMRSs) are fabricated for the first time. NMRSs can be decomposed to generate the template mesopore in situ during the pyrolysis of carbon precursors. Moreover, NMRSs also can work as a nitrogen‐dopant for porous carbons. As a demonstration, the N,P‐codoped hierarchically porous carbons are prepared using NMRSs as both pore‐forming agent and dopant, which exhibit excellent catalytic performances for the oxygen reduction reaction (ORR), close to or better than those of the best performing metal‐free doped carbon catalysts for the ORR. Therefore, this bifunctional template paves a facile pathway to fabricate porous carbons.