Rapid and sensitive diagnostics in the early stage of bacterial infection and immediate treatment play critical roles in the control of infectious diseases. However, it remains challenging to develop integrated systems with both rapid detection of bacterial infection and timely on-demand disinfection ability. Herein, we demonstrate a photonic hydrogel platform integrating visual diagnosis and on-site photothermal disinfection by incorporating Fe3O4@C nanoparticles into a poly(hydroxyethyl methacrylate)-co-polyacrylamide (PHEMA-co-PAAm) matrix. In vitro experiments demonstrate that such a hydrogel can respond to pH variation caused by bacterial metabolism and generate the corresponding color changes to realize naked-eye observation. Meanwhile, its excellent photothermal conversion ability enables it to effectively kill bacteria by destroying cell membranes under near-infrared irradiation. Moreover, the pigskin infection wound model also verifies the bacterial detection performance and disinfection ability of the hydrogel in vivo. Our strategy demonstrates a new approach for visual diagnosis and treatment of bacterial infections.