How do they get the radio versions of songs?

For those not in the US where curse words are censored in songs on the radio, there is sometimes an alternate version with a non-swear phrase

How are these made? Does the artist have to record the song twice? Or just another part and then it’s stitched in?

The radio and explicit versions sound identical except for any swearing segments?