How To: Add custom PHP code to WordPress

It’s usually a very good idea to add custom PHP code to WordPress instead of using plugins. 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.

Snippet Vault

You can install it from the WordPress Repository, it’s here. Then, here is how 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 ran 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 time 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 to add code directly in your functions.php if the code is extremely dependent of 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 update it, then your changes are gone.

Go for Code Snippets. Except if you know exactly what you are doing. But in that case, why did you check that article? 😋