The photoreduction of CO2 to hydrocarbon products has attracted much attention because it provides an avenue to directly synthesize value‐added carbon‐based fuels and feedstocks using solar energy. Among various photocatalysts, graphitic carbon nitride (g‐C3N4) has emerged as an attractive metal‐free visible‐light photocatalyst due to its advantages of earth‐abundance, nontoxicity, and stability. Unfortunately, its photocatalytic efficiency is seriously limited by charge carriers′ ready recombination and their low reaction dynamics. Modifying the local electronic structure of g‐C3N4 is predicted to be an efficient way to improve the charge transfer and reaction efficiency. Here, boron (B) is doped into the large cavity between adjacent tri‐s‐triazine units via coordination with two‐coordinated N atoms. Theoretical calculations prove that the new electron excitation from N (2px, 2py) to B (2px, 2py) with the same orbital direction in B‐doped g‐C3N4 is much easier than N (2px, 2py) to C 2pz in pure g‐C3N4, and improves the charge transfer and localization, and thus the reaction dynamics. Moreover, B atoms doping changes the adsorption of CO (intermediate), and can act as active sites for CH4 production. As a result, the optimal sample of 1%B/g‐C3N4 exhibits better selectivity for CH4 with ≈32 times higher yield than that of pure g‐C3N4.