Build Your Own Business Website header image

Lesson 9 – Part 3 – Introduction to Action Hooks

Difficulty Level -

Filed Under Topics - , ,

Listed Under Lesson Subjects -

Applies to -

The next thing we’re going to talk about is action hooks. Action hooks are fundamental to customizing Thesis. If you’re going to customize the Thesis theme using PHP, you are going to be using an action hook and you’re going to be using it, essentially with each part of customization that you do.

People, I think, find action hooks a little bit confusing but I think mostly, they find it confusing because people say it’s confusing and so you start off thinking about it as confusing. So maybe now I’ve already made you think maybe the action hook is confusing. But in fact, I think the concept of action hooks is actually pretty simple.

What is an Action Hook?

An action hooks is a WordPress function and that WordPress function is a place holder in the sequence of the code that allows you to add your own functions or to remove someone else’s functions.

WordPress processes maybe 100,000 instructions in order to put out a page and it does so in a given sequence. So there’s the first thing it does and then the second thing it does and then the 3rd thing it does until it’s done with all of its actions.

And that sequence is always the same or given the kind of page it is, that sequence is always the same. And so in that sequence, WordPress has inserted these placeholders where you can get to that sequence of code instruction and you can insert your own code or you can subtract somebody else’s code.

You can think of this as the bus stop. If someone is waiting at the bus stop then the bus is going to stop to pick them up. And if someone’s on the bus and wants to get off the bus then the bus stops at the bus stop to drop them off. And if no one wants on or off the bus, the bus just passes by without stopping.

WordPress is like a bus route, in that case, where the end destination of that bus route is the page being rendered. And it has hundreds of stops along the way where if somebody wants to get on the bus, the bus will stop and let them on. And if somebody wants to get off the bus, the bus will stop and let them off. And it gets to those stops in the same sequence every time.

And so that’s what an action hook is. An action hook is this bus stop and it’s the point at which you’re going to insert your code in a sequence of code or you’re going to remove somebody else’s code from that sequence of code. That’s what an action hook is.

Action Hooks and the Thesis Theme

The action hook is an example of this advanced concept that’s available in the Thesis method that is not available if you’re using a traditional method of learning PHP because the ability to create an action hook is a very advanced concept. And you have months and months or years of instruction and practice before you get to the point where you can create an action hook.

Whereas all the action hooks are already created for you and so you just have to know when the action hook fires and you can tack on a very complex to thing to it or you can tack on a very simple thing to it.

But you don’t have to know how to create the action hook. All you have to know is the very simple process of attaching your function to that hook. So this is one of those places where it makes sense if you’re learning to customize Thesis, to learn a very advanced concept simply by using this very advanced tool that is an action hook.

3 Good Reference Guides on Action Hooks

There are 3 good reference guides for understanding and using action hooks because there are WordPress action hooks and there are Thesis action hooks. WordPress action hooks will fire no matter what theme you happen to be using. So if you’re using a Genesis theme, the same WordPress action hooks are going to fire in the Genesis theme and in the Thesis theme.

However, Thesis action hooks only fire if you’re using Thesis and do not fire if you aren’t using Thesis so the same thing is true with Genesis action hooks. They fire when you’re using Genesis but not when you’re not using Genesis.

WordPress Codex

So sort of the granddaddy of this really is the WordPress action hooks and you can find these WordPress action hooks in the codex. Under Lesson 9, which is this is the course page for this session, I have a bunch of things that you can use as reference, for example, the slides today, the lecture notes. I have a practice file that you can download and then there’s this link to the action hook reference in the WordPress codex.

The WordPress Codex is not a great place to learn how to use the action hooks because it’s not written for beginners. However, it is a good place for you to see the sequence of action hooks that fire during a typical WordPress request.

In this case, this is what happens if somebody goes to the homepage. The first thing is it checks to see whether or not there’s a network installation of WordPress. And if so, it loads the network plugins. And then it registers the taxonomies and then it registers the post types and then it loads the regular plugins and so on and so forth. So these are each action hooks in the process of rendering a WordPress page.

Thesis User Guide

The second reference is the Thesis hooks reference in the user guide. This is an alphabetic listing of the Thesis theme hooks that are available to you. It doesn’t necessarily show them in the process of when they are fired.

Visual Hook Reference Guide

But Phil has come up with this very nice little website. Phil is a very helpful gentleman on the DIY Themes forums and Phil has this great visual hook reference guide where you can see where each of these hooks are in the context of a page.

So Thesis hook before HTML, Thesis hook first nav item, last nav item, before the header, before the title, after the title, the header, after the header, so on and so forth. So if you ever need to see where a specific hook is fired in the context of a page, hooks.thesislab.net is the place to go. Phil’s done an excellent service in providing this for us. Those are the references that I recommend that you use.

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
THIS IS A LIMITED TIME OFFER!
Subscription Options
0 Comments… add one
0 comments… add one

Leave a Comment