Core–shell structured photoresponsive molecularly imprinted polymers were developed for the determination of sulfamethazine in milk samples. The photoresponsive imprinted polymers were prepared with polymethyl methacrylate containing a mass of ester groups as core, sulfamethazine as template molecules, self‐synthesized water‐soluble 4‐[(4‐methacryloyloxy)phenylazo] benzenesulfonic acid as a photoresponsive monomer, and ethylene dimethacrylate as cross‐linker. Interestingly, the imprinted polymer can specifically adsorb sulfamethazine under dark and 440 nm irradiation, and release it at 365 nm. A series of adsorption experiments showed that the maximum adsorption capacity reached 12.5 mg⋅g–1, and the adsorption equilibrium was achieved within 80 min. Moreover, the imprinted polymers display excellent reusability, with almost no performance loss after four times photo‐controlled adsorption‐release cycles, and the imprinted polymers have excellent selectively for sulfamethazine (imprinting factor = 3.01). In the end, the imprinted polymers realized effective separation and enrichment of sulfamethazine in milk, with a recovery rate of over 97.5%. The material can be used as a solid‐phase extractant in the process of enrichment and separation for the quantitative detection of sulfamethazine in milk samples.