Endophthalmitis, derived from the infections of pathogens, is a common complication during the use of ophthalmology‐related biomaterials and after ophthalmic surgery. Herein, aiming at efficient photodynamic therapy (PDT) of bacterial infections and biofilm eradication of endophthalmitis, a pH‐responsive zeolitic imidazolate framework‐8‐polyacrylic acid (ZIF‐8‐PAA) material is constructed for bacterial infection–targeted delivery of ammonium methylbenzene blue (MB), a broad‐spectrum photosensitizer antibacterial agent. Polyacrylic acid (PAA) is incorporated into the system to achieve higher pH responsiveness and better drug loading capacity. MB‐loaded ZIF‐8‐PAA nanoparticles are modified with AgNO3/dopamine for in situ reduction of AgNO3 to silver nanoparticles (AgNPs), followed by a secondary modification with vancomycin/NH2‐polyethylene glycol (Van/NH2‐PEG), leading to the formation of a composite nanomaterial, ZIF‐8‐PAA‐MB@AgNPs@Van‐PEG. Dynamic light scattering, transmission electron microscopy, and UV–vis spectral analysis are used to explore the nanoparticles synthesis, drug loading and release, and related material properties. In terms of biological performance, in vitro antibacterial studies against three kinds of bacteria, i.e., Escherichia coli, Staphylococcus aureus, and methicillin‐resistant S. aureus, suggest an obvious superiority of PDT/AgNPs to any single strategy. Both in vitro retinal pigment epithelium cellular biocompatibility experiments and in vivo mice endophthalmitis models verify the biocompatibility and antibacterial function of the composite nanomaterials.