This work presents a simple way to prepare boron-doped graphitic carbon nitride (B/g-C3N4), exhibiting an enhanced photocatalytic performance to split water for hydrogen production. B/g-C3N4 was synthesized via the pyrolysis of urea and 1-ethyl-3-methylimidazolium tetrafluoroborate ([Emim]BF4), which was adopted as the boron source. The aggregate of B/g-C3N4 nanosheets shows a porous structure since some bubbles are generated under the heat decomposition of ionic liquids. The porous structure is conducive to the exposure of more active sites. Moreover, B-doping will form some localized electronic energy levels in the band gap of g-C3N4, thereby extending its visible light response. As impacted by the porous structure of B/g-C3N4 aggregate and the narrow the band gap, the photocatalytic hydrogen generation rate (901 μmol h−1 g−1) is increased, almost 3 times faster than g-C3N4 (309 μmol h−1 g−1). This work proposed a simple method to prepare the aggregate of B/g-C3N4 nanosheets exhibiting pores under ionic liquid assistance. It can be a novel method to design porous polymer photocatalysts. © 2021 Elsevier Ltd