In extreme cases my go-to is to drink an inordinate amount of water and use a suppository.
If you don't quite feel like you're there yet, try adding Benefiber to your diet and see if that helps. Again, drink water, both of those options need water to work.
Other tips, don't strain. I know sometimes you're just so desperate to get something, anything out, but it causes your rectum to swell, which leads to more constipation, and hemorrhoids. Just wait until you feel an urge, and practice "breathing the baby out" this is also good practice for labor.
Drink water throughout the day! Try drinking less liquids before bed
I see an acupuncturist who helps enormously in this department. Like a Christmas miracle. There are many acupuncturists who specialise in fertility and pregnancy support so they understand you particular needs and can help with other preg symptoms. Also 2nd the advice on fiber supplements such as benefibre or metamucil, but youll need to take these 3 times a day if the situation is bad.
Stool softeners are safe. I drank miralax and warm milk. Also eating jello helps as well because the gelatin keeps your intestines lubed by retaining the water.
I always had a problem with constipation ever since I was young but now that I'm pregnant I am feeling it worse than ever, my mom had the same problem. But recently I started eating chia seed with my yogurt and some fiber gummies, I've been going to the bathroom for number 2 at least every other day. So that might be something to do.