Here are some potential solutions:
1. Make sure that your headphones are properly plugged in. Try blowing gently into the port to make sure nothing is stuck in it.
2. Try a simple restart by holding down the Power button for 10 seconds or so, or until the Moto G4 goes off and comes back to life.
3. Make sure that you test your headphones with another device and test different headphones with your Moto G4. Quite a few people report that some headphones work and others simply don’t.
4. A third-party app could be causing your problem. Press the Power key, then tap and hold on Power off and tap OK when Reboot to safe mode appears. The Moto G4 will reboot and you should see Safe Mode in the bottom-left corner. If your headphones work properly, then a third-party app is probably to blame for your problem. You can simply restart the phone to get out of safe mode. Try uninstalling apps one by one, starting with anything that has an obvious audio component. Restart your phone after each uninstall and test to see if the problem is resolved.