Head loose. Hold hammer, head up, on a firm base. Drive small metal wedges, available from hardware store, into top of handle. You can also use hardwood wedges, but in this case it is necessary first to make a small split in the top of handle.
Handle broken. Saw off handle just below head. Then drive rest of handle out through bottom of head. Shape new handle to fit with a rasp, drive into head, and secure with a metal wedge.