Pluronic 31R1 and MCM41 were utilized to synthesize mesoporous MgFe2O4/g-C3N4 heterostructures. The employed approach yields a high surface area product (120 m2g-1) with a bandgap (2.58 eV) that allows photocatalysis in the visible light regime. TEM images show an even distribution of spherical MgFe2O4 particles with sizes within the ∼10–15 nm range. Magnetization values of 44.0 emu g−1 for the optimal 3% MgFe2O4/g-C3N4 heterostructure were high compared to what have been reported. The photocatalytic ability MgFe2O4/g-C3N4 nanocomposite was greater than that of pure MgFe2O4 or g-C3N4. A tenfold increase in CIP photooxidation efficiency results from incorporation of MgFe2O4 nanoparticles onto g-C3N4 with a percentage concentration of 0–4%. The optimum photocatalyst concentration used was 1.6 g/L for a fast reaction time of 120 min. CIP photooxidation efficiency when using mesoporous 3% MgFe2O4/g-C3N4 was 100% while it was 10% for pure g-C3N4 and 18% for pure MgFe2O4. High dispersion of spherical MgFe2O4 nanoparticles on the surface of g-C3N4, the high surface area, narrow bandgap, the heterostructure that allows unhindered diffusion of CIP into the pore structure, and the superior charge-carrier separation ability resulted in the enhanced photocatalytic ability. Magnetic properties resin from MgFe2O4 addition facilitate the easy separation of the photocatalyst and allowing its recycling.