If you prefer to use a plugin, there is https://wordpress.org/plugins/advanced-custom-fields/ that is very popular. I personally have never used it, so I can’t give you too much information about it. You would have to check it out for yourself to see if it would do what you want.
I have used ACF and I can say that it’s quite a well done plugin, as far as I’ve seen, and it’s pretty versatile. Even if you do know how to get it done with custom code, there’s something to be said for speed too, if you need a lot of custom fields. For just the one… maybe not, I dunno.