Your code will only do what you need and what you want, and keep your WordPress install light. For me, there are two main ways of adding custom PHP code to WordPress. I’ll start with my most recommended one.
I truly love this plugin, it’s perfection. If it disappears one day, I’ll code it right away, and just the same. You can install it from the WordPress Repository, it’s here. Then, here is what it looks like in WordPress:
You can see what I did with it, like above. You can use this to customize almost everything about your WordPress or modify the behavior of certain plugins, like mine. You can also choose whether you would like those snippets to be run all the time, or maybe only on the front end or only on the back-end.
I recommend you to use this. It will follow your website when you migrate it, you can see at all times your code snippets and even name them, it’s really tidy.
Or, into the depth of the functions.php!
In your theme, there is a functions.php file. It’s probably already full of code, but it’s pretty common to add some additional code in there, at the end of it.
I only recommend you add code directly in your functions.php if the code is extremely dependent on the theme itself and/or if it’s your own theme, made specifically for your website. Also, if someone, like a developer or the theme maker, updates it, then your changes are gone.