This little module plugs into the Raspberry Pi GPIO header (or can be soldered if mounted elsewhere) and provides a safe way to shutdown the Raspberry Pi and cuts power completely.
Just add the following lines of code to your /boot/config.txt file:
#Shutdown Button
dtoverlay=gpio-shutdown,gpiopin=3
#Poweroff Trigger
dtoverlay=gpio-poweroff,gpiopin=4