In this article, I’m going to give you a “mildly technical” WordPress primer. It’s not going to make you a rockstar developer, but it will help you understand a little bit about how your site works and what you need to know to customize it.
Using Custom Code In WordPress
Before I can properly cover what to do with custom code you might want to use on a WordPress site, let’s cover a few basics up front. These may be too basic for some, but many of them are things I didn’t know when I started making sites. These concepts are, in my mind, essential for anyone making WordPress sites.
What Language Does WordPress Use?
Understanding what the four languages do, and where they run is essential for understanding what type of code you are looking for. When you understand the different responsibilities each have, then it will be easier to think of what type of code needs changed to achieve a goal.
WordPress is event-driven. By that, I mean that there are a series of events that you can use to add new functionality or modify functionality. Server-side, WordPress uses a system of “hooks” to allow you to change the value of something — we call these filters — or doing something at a specific point — we call these actions.
Think of hooks this way: they are stopping points that invite others to do something. When WordPress gets to a hook, it checks if any other functions are hooked to the current filter or action, and if so all of those functions are called before moving on.
Most of the time when you are applying custom code to a WordPress site, it involves using a hook. We call the system of hooks the “Plugin API” and it is one of the most fundamental things about WordPress that you need to understand. Seriously, it is worth investing time in understanding the WordPress plugins API.
An example of using a hook, would be if someone tells you to add some code, such as Google Analytics tracking code to your page’s header. Every WordPress theme should call the action “wp_head” before the closing HTML head tag. You can hook into wp_head and echo your analytics code there.
While actions allow you to do something at a certain time, filters allow you to modify something specific. For example, if you wanted to add some additional content, such as information about a service or a link to a signup form, you could use “the_content” filter. This filter gives you the content of whatever post is being shown and you can modify, replace, or add new content to it.
What’s the Best Way to Add Custom Code to WordPress?