How do I change the element using a custom function?

If an incorrect <title> tag has been added to the header template the only option that will work is the child theme method. You can’t override template markup with a custom function.

If you do use a child theme then don’t use wp_title(), just remove the title tag entirely and register support for support title-tag.