A search for massive resonances decaying to a Z boson and a photon is performed in events with a hadronically decaying Z boson candidate, separately in light-quark and b quark decay modes, identified using jet substructure and advanced b tagging techniques. Results are based on samples of proton–proton collisions collected with the CMS detector at the LHC at center-of-mass energies of 8 and 13TeV, corresponding to integrated luminosities of 19.7 and 2.7 fb−1, respectively. The results of the search are combined with those of a similar search in the leptonic decay modes of the Z boson, based on the same data sets. Spin-0 resonances with various widths and with masses in a range between 0.2 and 3.0TeV are considered. No significant excess is observed either in the individual analyses or the combination. The results are presented in terms of upper limits on the production cross section of such resonances and constitute the most stringent limits to date for a wide range of masses.