Instead of muffin pans, use Mason (canning) jar rings when baking muffins or cupcakes. I use wide-mouth rings for jumbo size muffin liners and regular-size jar rings for standard-size liners.
Set the jar rings right-side-up on a cookie sheet. Set the liners in the rings then fill with batter as you would with a muffin pan. The muffins or cupcakes are sure to stay in place.
The bonus with this hack is that you can make way more muffins or cupcakes at once on a cookie sheet than with a muffin pan.