Recently I accidentally overwrote my Production site when I thought I was on the staging site so after a bit of googling I came up with this solution. If you are on WordPress you can just paste this at the end of your functions.php for your theme. This could also probably be turned into a very simple plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters