A small plugin or functions.php?
Theme functions.php
Snippets vanish when the theme updates
or when you switch themesA file in mu-plugins
Works with any theme
Cannot be deactivated by mistake from the plugins pageUpload the file to wp-content/mu-plugins (create the folder if missing). It runs at once with no activation. If an error appears, delete or rename the file to restore the site, and see the syntax error guide.