Pressure fluctuations play an essential role in the transport of turbulent kinetic energy and vibrational loading. This study focuses on examining the effect of wall cooling on pressure fluctuations in compressible turbulent boundary layers by high-fidelity direct numerical simulations. Pressure fluctuations result from the vorticity mode and the acoustic mode that are both closely dependent on compressibility. To demonstrate the effects of wall cooling at various compressibility intensities, three free-stream Mach numbers are investigated, i.e. $M_\infty =0.5$ , 2.0 and 8.0, with real gas effects being absent for $M_\infty =8.0$ due to a low enthalpy inflow. Overall, opposite effects of wall cooling on pressure fluctuations are found between the subsonic/supersonic cases and the hypersonic case. Specifically, the pressure fluctuations normalized by wall shear stress $p^\prime _{rms}/\tau _w$ are suppressed in the subsonic and supersonic cases, while enhanced in the hypersonic case near the wall. Importantly, travelling-wave-like alternating positive and negative structures (APNS), which greatly contribute to pressure fluctuations, are identified within the viscous sublayer and buffer layer in the hypersonic cases. Furthermore, generating mechanisms of pressure fluctuations are explored by extending the decomposition based on the fluctuating pressure equation to compressible turbulent boundary layers. Pressure fluctuations are decomposed into five components, in which rapid pressure, slow pressure and compressible pressure are dominant. The suppression of pressure fluctuations in the subsonic and supersonic cases is due to both rapid pressure and slow pressure being suppressed by wall cooling. In contrast, wall cooling strengthens compressible pressure for all Mach numbers, especially in the hypersonic case, resulting in increased wall pressure fluctuations. Compressible pressure plays a leading role in the hypersonic case, mainly due to the APNS. Essentially, the main effects of wall cooling can be interpreted by the suppression of the vorticity mode and the enhancement of the acoustic mode.