OH is a key species in the water chemistry of star-forming regions, because its presence is tightly related to the formation and destruction of water. This paper presents OH observations from 23 low- and intermediate-mass young stellar objects obtained with the PACS integral field spectrometer on-board Herschel in the context of the Water In Star-forming Regions with Herschel (WISH) key program. Most low-mass sources have compact OH emission (< 5000 AU scale), whereas the OH lines in most intermediate-mass sources are extended over the whole PACS detector field-of-view (> 20000 AU). The strength of the OH emission is correlated with various source properties such as the bolometric luminosity and the envelope mass, but also with the OI and H2O emission. Rotational diagrams for sources with many OH lines show that the level populations of OH can be approximated by a Boltzmann distribution with an excitation temperature at around 70 K. Radiative transfer models of spherically symmetric envelopes cannot reproduce the OH emission fluxes nor their broad line widths, strongly suggesting an outflow origin. Slab excitation models indicate that the observed excitation temperature can either be reached if the OH molecules are exposed to a strong far-infrared continuum radiation field or if the gas temperature and density are sufficiently high. Using realistic source parameters and radiation fields, it is shown for the case of Ser SMM1 that radiative pumping plays an important role in transitions arising from upper level energies higher than 300 K. The compact emission in the low-mass sources and the required presence of a strong radiation field and/or a high density to excite the OH molecules points towards an origin in shocks in the inner envelope close to the protostar.