Whenever you face the need to make customizations directly to your website’s core files, especially to the functions.php
file ⚠️, it is recommended that you create a child theme for that purpose. Child themes can help isolate the code from the main site and preserve the changes you made even after a major WordPress upgrade.
For more information on WordPress child themes, check out the Child Themes page from the Theme Developer Handbook.