Central compact objects (CCOs) are X-ray sources lying close to the centre of supernova remnants, with inferred values of the surface magnetic fields significantly lower (≲1011 G) than those of standard pulsars. In this paper, we revise the hidden magnetic field scenario, presenting the first 2D simulations of the submergence and re-emergence of the magnetic field in the crust of a neutron star. A post-supernova accretion stage of about 10−4–10−3 M⊙ over a vast region of the surface is required to bury the magnetic field into the inner crust. When accretion stops, the field re-emerges on a typical time-scale of 1–100 kyr, depending on the submergence conditions. After this stage, the surface magnetic field is restored close to its birth values. A possible observable consequence of the hidden magnetic field is the anisotropy of the surface temperature distribution, in agreement with observations of several of these sources. We conclude that the hidden magnetic field model is viable as an alternative to the antimagnetar scenario, and it could provide the missing link between CCOs and the other classes of isolated neutron stars.