We present a modelling study of locomotion over a layer of viscoplastic fluid motivated by the self-propulsion of marine and terrestrial gastropods. Our model comprises a layer of viscoplastic mucus lying beneath a fluid-filled foot that is laced internally by muscular fibres under tension and overlain by the main body of the locomotor, which is assumed to be rigid. The mucus is described using lubrication theory and the Bingham constitutive law, and the foot using a continuum approximation for the action of the muscle fibres. The model is first used to study the retrograde strategy of locomotion employed by marine gastropods, wherein the muscle fibres create a backwards-travelling wave of predominantly normal displacements along the surface of the foot. Once such a retrograde forcing pattern is switched on, the system is shown to converge towards a steady state of locomotion in a frame moving with the wave. The steady speed of locomotion decreases with the yield stress, until it vanishes altogether above a critical yield stress. Despite the absence of locomotion above this threshold, waves still propagate along the foot, peristaltically pumping mucus in the direction of the wave. The model is next used to study the prograde strategy employed by terrestrial gastropods, wherein the muscle fibres create a forwards-travelling wave of predominantly tangential displacements of the foot surface. In this case, a finite yield stress is shown to be necessary for locomotion, with the speed of locomotion initially increasing with the yield stress. Beyond a critical yield stress, localized rigid plugs form across the depth of the mucus layer, adhering parts of the foot to the base. These stop any transport of mucus, but foot motions elsewhere still drive locomotion. As the yield stress is increased further, the rigid plugs widen horizontally, increasing the viscous drag and eventually reducing the speed of locomotion, which is therefore maximized for an intermediate value of the yield stress.