Heavy ab work. For me, front squat holds seem to have helped a lot.
I’ll try to explain the following mobility stretch, but if I mess it up, I’ll try to get a picture of it next week.
I take a strong band and anchor it to something (I use a squat rack) at about shin height. Step into the loop and pull it up so that it’s around the very top of your leg, pretty much sitting right below your hip. Then walk it forward (so that there’s tension pulling your leg back) and get into your squat stance. From there, squat down (you’ll need to lean forward or else you’ll eat it) and lean forward on your hands so that you’re in a mountainclimber position. Then shift backwards so that your legs are bent (as if you were in the bottom of a squat). Simultaneously shift your weight to the side of your body that the band is on and dip your shoulder so that it’s next to your knee.
Once you’re in that weird position and have the band pulling your hip back (what feels like out of its socket), shift your weight from side to side, front and back, circle (clockwise and counter clockwise) and just move it around until it loosens up a bit. This helps me keep my knees out and my hips closer to being directly under the bar.
Let me know if that’s confusing. It likely is, haha
Also, flaring your toes out can help with this if it helps you keep your knees out. If your knees are pointing more out than forward, you’ll squat straight down and be more upright. (As opposed to sitting back and leaning forward.) That stance requires good mobility, though. Also, you can lose some torque in your hips from pointing your toes out like that. It’s worth a shot, though.