Definitely sideways. Make sure you re-aim and use a lofted wedge. Backwards works too. You can use the reverse green view camera, if available, to help the aim.
This isn't automatic when you find yourself in a trap. Sometimes you're OK to go straight. The key is the loft of the club you're trying to get out with and how close you are to the wall. But when you're jammed up tight you have no other choice.