Hello.
In order to make this work, I would create a child theme (if possible), and implement the functions there. If creating the child theme is not possible, then I would need to change the theme files. If that is the case, then any update of the theme would erase the changes we make to it.
But, in general, child theme is supported by most of modern themes.
Regards,
Nikola