There are a lot of reasons to love WordPress, but one of the reasons I keep WordPressing is the supportive community. While I have no formal training as a web developer, I don’t like describing myself as “self-taught.” I didn’t figure this out on my own, I was taught by a supportive community that filled the Internet and WordCamp with everything I ever need to know.
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. Next week, I will follow up with an article on how to put this knowledge to work when evaluating and implementing those code snippets that you find on the internet and think will help solve your problems.
Before I do that, I want to say that if you make websites, then in my mind, you are a web developer, whether you write code or not. Whether you are a “site builder” that doesn’t write code or a programmer doesn’t matter. If you make WordPress sites, then you’re going to have to be able to evaluate suggestions that involve adding code to your site that can have real consequences.
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. I have a short introduction to the topic and Tom McFarlin has a longer introduction, both of which are beginner friendly.
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?
Next week, I will be covering what to do with custom code you might want to add to your WordPress site. This article should have prepared you to know what kind of code you need and be more prepared to evaluate, test and implement that code.
I hope this article has helped you understand a little more about how WordPress works. My goal wasn’t to make you an expert programmer. Instead I am hoping that I helped you understand a bit more of which of the four languages in WordPress are responsible for what, so you will be better prepared to modify WordPress’ behaviour to fit your needs.