My daughter was given watered down & then straight prune juice at about the same age for the same problem, it took time but worked. Although until she was about 3 we still had to give it to her regularly & sometimes had to use a suppository (script from dr) as in her case the problem was that the muscles at the "mouth" of the anus just didn't(& don't - she's 15) work properly.
You might consider if bottle fed trying a different formula (non-dairy?) or if breast fed then it may be something the mum has that the baby doesn't like.
Also some children need fibre (solids) sooner than others my son started on solids at 2 weeks of age. My daughter at about 8 weeks.