Attaching ribbon to hat

I am starting the baby hat and I am suppose to attach a ribbon to each side for tying. I have cut ribbon before and it always freys on me. I even cut it with picking shears and it still freys. Is it better and easier to attach and piece of yarn knitted? How would I do that?

You could do i-cord, I suppose, but I think ribbon would be nicer. To stop it from fraying, get a lighter and hold a flame near the cut edge of the ribbon for a couple of seconds. It shouldn’t be close enough to light or even singe, but the edge will kind of shrink away from the flame just the tiniest bit. Blow on it and then touch it, trying to fray the edge with your fingers, and if it frays, cut off the last 2 millimetres and try again. You should feel the edge of the ribbon slightly plastic-y.

Is there a neat way of sewing it on? Do you just whip stitch it?