Aims. We present a framework to obtain photometric redshifts (photo-zs) for gamma-ray burst afterglows. Using multi-band photometry from GROND and Swift/UVOT, photo-zs are derived for five GRBs for which spectroscopic redshifts are not available. Methods. We use UV/optical/NIR data and synthetic photometry based on afterglow observations and theory to derive the photometric redshifts of GRBs and their accuracy. Taking into account the afterglow synchrotron emission properties, we investigate the application of photometry to derive redshifts in a theoretical range between z ∼ 1 to z ∼ 12.Results. The measurement of photo-zs for GRB afterglows provides a quick, robust and reliable determination of the distance scale to the burst, particularly in those cases where spectroscopic observations in the optical/NIR range cannot be obtained. Given a sufficiently bright and mildly reddened afterglow, the relative photo-z accuracy η = Δz/(1 + z) is better than 10% between z = 1.5 and z ∼ 7 and better than 5% between z = 2 and z = 6. We detail the approach on 5 sources without spectroscopic redshifts observed with UVOT on-board Swift and/or GROND. The distance scale to those same afterglows is measured to be z = 4.31 +0.14 −0.15 for GRB 080825B, z = 2.13 +0.14 −0.20 for GRB 080906, z = 3.44 +0.15 −0.32 for GRB 081228, z = 2.03 +0.16 −0.14 for GRB 081230 and z = 1.28 +0.16 −0.15 for GRB 090530. Conclusions. Due to the exceptional luminosity and simple continuum spectrum of GRB afterglows, photometric redshifts can be obtained to an accuracy as good as η ∼ 0.03 over a large redshift range including robust (η ∼ 0.1) measurements in the ultra-high redshift regime (z 7). Combining the response from UVOT with ground-based observatories and in particular GROND operating in the optical/NIR wavelength regime, reliable photo-zs can be obtained from z ∼ 1.0 out to z ∼ 10, and possibly even at higher redshifts in some favorable cases, provided that these GRBs exist, are localized quickly, have sufficiently bright afterglows and are not heavily obscured.