10 Ways to Learn WordPress Hooks

Reading Time: 9 mins

WordPress Hooks are hard. We always hear the word “hooks” being thrown around and it’s one of those things that make sense, but then it doesn’t.

I’m sure that there may even people reading this right now, and not entirely sure what I mean by hooks. That’s okay. Before I go on with this post, they look like this. These are two examples I pulled from the Twenty Fifteen Theme in functions.php.

Line 142 of functions.php in Twenty Fifteen.

Line 142 of functions.php in Twenty Fifteen, it’s an action hook.

Line 310 of functions.php in Twenty Fifteen.

Line 310 of functions.php in Twenty Fifteen, it’s a filter hook.

 

Still confused? No worries, it took me a while too. In fact, I can’t say that I completely know all there is to know about WordPress hooks even now, even after writing, “The WordPress Hooks Firing Sequence“. WordPress is the kind of thing that the goal isn’t to learn it all, but to learn it in levels for your purposes. It’s such a deep system, deeper than most people imagine, and I’ve found that once I’ve obtained an understanding of one concept, there is always more to learn. Each concept I learn serves as a foundation for what I learn next.

Hooks didn’t click for me until about a year ago. I too, was copying and pasting various solutions offered by the all knowing Google or Stack Overflow into my WordPress theme. I hadn’t truly understood what was happening when I dropped these snippets of PHP in and the world that would open once that understanding happened.

As much as I’d like to sit here and try to explain what hooks are, if there’s one thing I can say from experience, is that understanding comes in layers. In other words, there is no one mind blowing resource that is suddenly going to make it click. Or maybe it will, depends on the person I guess. For me, however, it took several readings, videos, and diving into WordPress code before the ah hah moment hit.

Knowing that it took a combination of resources and methods for me to learn WordPress hooks, I’d like to pass them onto you. These resources will hopefully bring that fuzzy definition of hooks into focus, even if it’s in layers. In addition to these 10 resources, I’d like to share 2 methods that worked for me. Everyone learns differently and at their own pace, but perhaps sharing my experience will help someone along.

Here are 10 resources about WordPress hooks, from newest to oldest. If you know of others, feel free to recommend in the comments.

  1. WPShout: WordPress Hooks, Actions, and Filters: What They Do and How They Work

    WPShout’s article was the final nail for me. Whatever shaky understandings I’d had up until that point were solidified with the help of their awesome factory analogies. This was also the first resource that I’d read that clarified the terminology used in the WordPress Codex wasn’t always consistent, therefore making the subject more difficult to learn. Realizing this was an epiphany of sorts! So if you’re confused by whether hooks are for plugins only, WPShout is going to break it all down in plain English. I’d recommend this as the starting point for anyone looking to learn WordPress hooks without all the heavy tech jargon.

  2. WPMUDEV: A Quick (and in-Depth) Guide to WordPress Hooks

    I like how this article introduces you to code snippets in core right away. For some, this may be more confusing off the bat, but for others, this method may work. This article guides the reader through some core examples that can be modified before clearly explaining what filters are, the terminology, and the difference between filters and hooks. If diving right into code before explanations sound more like your style, might want to give this a read.

  3. Team TreeHouse: WordPress Hooks: Actions, Filters, and Examples

    I like how TreeHouse gets to the point on hooks. They give a brief explanation and offer code snippets, but the goal is to point you to the WordPress Codex. This way you can just dive into code and get a feel for how things work yourself. I learned from here that filter hooks are categorized depending on whether the code is reading from the database before the hook does anything or the hook does something after the database has saved data. I didn’t know that before I wrote this post! 🙂 If databases sound foreign, and some of those code snippets appear intimidating, this may be a resource better left bookmarked for later once you have some PHP basics mastered.

  4. TutsPlus: Fifty Actions of WordPress Series

    This series is one of the most amazing series written on TutsPlus. Before I’d written my long post with hook sequences using a debug tool to find them, this was a great reference to commonly used hooks. After the introduction and a brief overview of creating your own action hook, the series takes you through learning action hooks from core, ten at a time. It shows you how to work with these hooks with real life examples. This is great for those who just don’t know where to start. With this series, you can learn a handful at a time, and by the end, you’ve familiarized yourself with fifty hooks you hadn’t known before.

  5. TutsPlus: Fifty Filters of WordPress Series

    This series written is written by the same author as the one above for actions, except for filter hooks. It’s awesome for all the same reasons. Learning how to use filter hooks ten at a time, with real life applications, and before you know it, you’ve got experience with fifty new hooks you hadn’t known existed.

  6. Smashing Magazine: A Definitive Guide to WordPress Hooks

    I like how Smashing Magazine provides a walkthrough of how to use the popular resource, Adam Brown’s Hook Reference. As I’d mentioned in my earlier post on hooks, this is a pretty overwhelming resource for me. However, for others, this may be helpful for those looking to use that reference.

  7. TutsPlus: Understanding Hooks from the Inside Out

    This article has it’s own theories for how developers should learn WordPress hooks. There’s some tech jargon in here that even I didn’t fully understand, but for those who are more solid in PHP, this may be a handy tutorial. This tutorial walks the reader through creating an email notification system.

  8. WP Candy: How to use WordPress Hooks

    This! This right here! This is the very first article I read that shed the light on hooks for me. I found it last year, but the moment I did, hooks became a very attainable concept to learn. It just made sense! It’s an older resource, and while WP Candy is no longer active, this article was the beginning of my understanding on hooks. The first layer being cleared.My favorite line is: “The way I like to explain action hooks, in a single sentence, is: ‘When you get to this point, do that.'” That got the message across for me.

  9. WP Candy: Custom Hooks and Pluggable Functions

    I read this right after the introduction preceding it. This article explains how to implement the actions you’ve created into the WordPress templates using do_action, and what pluggable functions are. It also explains when to use either a hook or pluggable function although pluggable functions are no longer encouraged nowadays. Pluggable functions have been removed from WordPress core. Using hooks instead are the recommended route to take.

  10. Press Customizr: WordPress Actions, Filters, and Hooks : A guide for non-developers

    I definitely like how this points out it’s for the average joes. Even for developers, some of the above resources I’ve recommended can be confusing. Either the terms are too heavy, or they’ve thrown code at the reader without always breaking it down piece by piece of how it reached that point. This is part of the reason I began blogging – because I too, learn better when something is explained as simple as possible. I need to see the process of how to get from point A to point B. Not just arrive at point B with the assumption that I, as a reader, should just know how we got there. Even when writing code, I tend to use the rubber ducky method, and explain what I’m trying to make happen without having to resort to words that need a dictionary. So this is another great starting point in addition to my recommendation up top from WP Shout when getting into hooks. My favorite line in this one is: Actions do stuff; filters change stuff. Sometimes I wish more tutorials wrote like that.

Of course, there are probably a lot more resources out there! The ones I’ve mentioned above vary in difficulty depending on how you learn. I admit that I only read the WP Shout and WP Candy articles from beginning to end. Everyone learns differently and in my case, gathering small pieces of understanding from other articles, and reading just those three entirely were what I needed to feel more comfortable with hooks.

Now to be clear, I say comfortable versus becoming a master. Why? Because I admit that I haven’t used all the hooks that exist and don’t use hooks all the time. It’s because there are a lot of hooks and in my line of work so far, I’ve only needed to use them when modifying a plugin. There’s only one case where I’ve really gotten the hang of hooks, and it’s one of the methods I want to recommend to others. Speaking of methods, let’s talk about those.

Method One:

The first method that really took the knowledge I’d already gained and put it into practice was this. I installed WooCommerce and learned how to modify it with hooks. For those who don’t know WooCommerce, it’s a popular e-commerce plugin that transforms your WordPress site into a store! The files in WooCommerce have several layers and are well documented inside. Using a combination of the Codex, WooCommerce’s documentation, and my understanding from WP Candy (from before WP Shout published their article), diving into WooCommerce felt like one big game of connect the dots. It really showed me how a piece of code went from template file, to hook, to function. By editing, removing, or moving pieces of the store enough times, I eventually got used to the patterns. You’ll understand if you give this a try.

It can be intimidating, and sometimes the existing documentation isn’t enough, but the experience was an eye opener for me.

Method Two:

The other method I’d recommend is if you find that you’re running into too many articles or courses that feel too advanced for your understanding, take a step back. I got into WordPress before I understood how to write PHP. I eventually got to a block where I couldn’t understand how to use certain functions or debug issues due to me diving into WordPress first without a solid foundation in PHP. That’s when I watched about a fourth of the PHP Fundamentals Course by Jeffrey Way.

Jeffrey Way is one of the best instructors I’ve come across in my development career. I really like how he walks his students through learning the topic without the assumption of what they already know. He will go over every detail. He will also go over different ways to do something, and if one way isn’t recommended, he’ll explain why. So you’re not just gaining an understanding of the topic, but being flexible enough to learn different methods as well as best practices.

This needed to go here for no other reason than me liking this gif…

 

I highly recommend this course from TutsPlus despite it being a little outdated. If PHP scares the hell out of you, Jeffrey Way is going to make the learning process as painless as possible. Anyway, so I only watched the course to a point where I had these “ah hah” moments, and then applied them to my work in building WordPress themes. When I eventually got to another point where I felt I couldn’t go further due to my PHP knowledge, I returned to the course, and picked up where I left off until I no longer felt blocked. Therefore I watched the course in pieces, put those pieces into practice until I needed to clear another blocker, and repeated the process. Each time, layer by layer, gaining a more solid understanding of not only PHP, but WordPress as a platform.

I also started watching PHP courses on Team Treehouse a few months ago. I like how Treehouse quizzes you between videos, has a workspace to put code into real live practice, and has subtitles on their courses. Although some of the stuff I’m watching on Treehouse, I’ve already gone over in the course from TutsPlus, hearing two different instructors explain things in different ways can also help solidify your understanding.

Learn in Layers – Take your Time!

So those are the two methods that have helped me learn how WordPress hooks work so far.

Modifying WooCommerce, and learning PHP in levels before putting it into practice. It’s better to have a solid understanding of your foundations than to have shaky understandings on as much as you can get your brain to wrap around.

As a developer, I always feel this pressure to learn as much as possible. There’s just so much to learn these days and we’re always rushing to learn this new tool or new concept to feel like we’re “in the know” without strong foundations. Being back in the market recently has further heightened this struggle with the laundry list of skill-sets and frameworks on job postings and recruiting emails. It’s overwhelming! If you’ve ever felt this way too, reading Tom McFarlin’s articles, Learning a New Programming Language and The Tension of Software Development helps to remind me I’m human. Take it one step at a time, every new thing you learn no matter how small you feel it is, is a victory! You’re not the same person today as you were yesterday.

I’d like to write a more in-depth post on what it’s like to learn from WooCommerce as a guide to hooks in the future. For now, I hope that the 10 WordPress resources I’ve provided get someone on the right track. I hope the methods that helped me, help someone clear some of those layers too. If you have any experiences or resources to share, I’d love to hear them. Good luck!