Phonon coupling effects in magnetic moments of magic and semimagic nuclei