Build Your Own Business Website header image

Lesson 9 – Part 7 – Question and Answer Session

Difficulty Level -

Rick: Okay so having said that, I need a show of hands. If you’ve got a question that you would like answered about the material that I’ve covered so far, would you raise your hand quickly? Wo has a question and Wo, I’ve just unmuted your microphone.

Wo: Hi, yes.

Rick: Hey Wo, how are you?

Wo: Fine. Thanks very much for this. I’m really impressed. It was on the list of the footer name and function names?

Where to Find Lists of the WordPress and Thesis Hooks

Rick: Yes, the list of Thesis hooks is here, in the hooks reference list. Let’s see, is there a default Thesis functions? That’s not the right one. I think there used to be a list of default Thesis functions.

Let’s see, see if we can find it just in the table of contents. Default hook usage in Thesis… this is not a complete list of Thesis functions because there are hundreds of Thesis functions and most of them are not actually hooked to anything and you won’t be able to hook them or unhook them. But nevertheless, you do have this list of the Thesis nav menu, Thesis default header, post tags, comments link, next previous post, that kind of thing. Actually, this is a much better list than it used to be. So this right here, the default hook usage in Thesis gives you that set of Thesis functions that are hooked to Thesis hooks.

Wo: Great stuff.

Rick: Now in terms of WordPress, the easiest way really to get a sense of what the sequence of WordPress hooks are is from here although this is not comprehensive. And the comprehensive WordPress hook list is not particularly accessible to beginners.

In the WordPress hooks database you can find every single hook in every version of WordPress and including which ones are new and which ones have been deleted and everything else. So this actually does show you in alphabetical order, not in sequence order, in alphabetical order all of the hooks that exist in WordPress.

The WordPress hooks are substantially undocumented. WordPress pretty much assumes that if you’re going to use a WordPress hook then you’ll open up the WordPress core and look and see what that hook does. So there’s not a lot of exhaustive information about how each of these hooks are used and many of these hooks have no documentation about them at all and the only way to know what they do is open up the code and interpret what the code says.

Wo: Great. Thanks, Rick.

Rick: Okay, you’re welcome.

Create Your Own Action Hook

Okay so Brian asks, “Why or when would you have an action hook without anything happening?” Well, WordPress is designed to be customized. WordPress itself uses lots of its own hooks. Having said that, it assumes or it makes assumptions about where a programmer might want a hook. And so it has created these hooks specifically for that purpose.

For example, I needed a hook here recently. I needed a hook for when somebody successfully logged in to my site. And WordPress anticipated that I would want or somebody like me would want to be able to do something once the login has been authenticated.

WordPress itself doesn’t do anything when it happens necessarily but it provides the opportunity for somebody. And so hooks are proposed by the community, really. The community says, “Gosh, wouldn’t it be great if we had a hook here?”

For example, a theme activation hook. There’s a big debate about whether or not there should be a theme activation hook, that is a hook that fires when the theme has been activated. There currently is no theme activation hook and because the high level development community is divided on that subject, there’s not going to be one in the immediate future.

And so in the class that I’m teaching on creating a child theme, one of the things I’m going to teach is how to create your own action hook and add it to the child theme so that when the child theme is activated, certain things can happen. And in particular, what we want to do is save the existing Thesis options and then overwrite those options with the theme options for the child theme.

And then we want a theme deactivation hook which also doesn’t exist so we’re creating one for the child theme. And so when the child theme is deactivated then it takes those saved Thesis options and restores the original Thesis options.

So there’s a case where an action hook doesn’t exist. I’m going to teach how to create an action hook. But the process of adding action hooks is part of the community. So people say, “Gosh, it would be great to have a hook that fired here.” And then it gets debated and then eventually gets added. But WordPress has this built in system for creating your own action hooks so you can piggy-back on to an existing action hook and then create a new one which is what I’ll be teaching.

What to Use for Editing the PHP Code

Okay let’s see. Denise raised her hand. Denise, I’ve just unmuted your microphone. Good morning, Denise.

Denise: Okay, my question was I’m a little confused as to where we edit this stuff. Is it NetBeans that we have to download to edit all these things?

Rick: Well, you need some kind of a file editor.

Denise: Okay.

Rick: NetBeans is the file editor that I recommend. NetBeans is the file editor that I use.

Denise: Okay. I just went to the website. There’s 5 different things to download for NetBeans.

Rick: So what you would download is the PHP version.

Denise: Okay, php. Perfect.

Rick: Right. The php version includes HTML, CSS, PHP and javascript. So it’s got everything in it.

Denise: Okayi, that’s perfect.

Rick: Great.

Are Tick Boxes in Thesis Related to Hooks

Rick: Jared says he is here so we’ll try him one more time. Good morning, Jared.

Jared: Can you hear me?

Rick: Yeah.

Jared: Oh wonderful. Well, the only thing not really new, it seems to me that the tick box is in Thesis or what did they have? Remove hooks?

Rick: You’re talking about inside of…

Jared: Thesis where you have a tick box.

Rick: Inside of Design Options, you mean?

Jared: I don’t know, anywhere.

Rick: Well, okay so under Thesis Design Options, you’re talking about things like this?

Jared: Yes.

Rick: No, these are not action hooks. These are options that you are setting that Thesis is going to use but they aren’t action hooks.

Jared: So hooks are action items?

What are Hooks and How do they Work?

Rick: Hooks are placeholders in the code, in the sequence of the code that allow you to insert your code within that sequence.

Jared: I’m confused by that. What I have going on is you say they’re a bus stop so it seems to me like you’re designing a bus stop.

Rick: You’re not designing a bus stop. You’re designing the person who gets on the bus or gets off the bus. The bus stop has already been designed for you. The bus stop is there. So the function you’re writing is the guy that gets on the bus.

Jared: That’s… it’s still confusing to me.

Rick: Well, if you imagine that you are baking bread and the first thing you do is measure out the ingredients and then you add the yeast to the water. And then you let the yeast activate and then you add the dry ingredients to the water and then you knead. Each one of those things happens in a sequence, right? You don’t knead before you add the dry ingredients to the wet ingredients.

So you have this sequence of events and a hook is a place where you might stop in that sequence to do something else. And when you add your function to that hook, what you are doing is adding a new thing at that point in the sequence. So for example, you might have a hook when it’s time to rise. So you’ve kneaded your bread and you’ve set it aside to rise. And that point, you have a hook. And now, you insert something else to that hook. Maybe it’s you know, mix yourself a cocktail or go do something else.

Jared: So hooks are placeholders and the kind of placeholder determines on the function that you put there?

Rick: Well, no. The sequence determines what you can do there. If you ask it to do something, it’s going to want to do it within that sequence. You could ask it to do something out of sequence and it wouldn’t or it would fail. But the hook doesn’t determine what you do. Your function determines what you do. The hook just determines where you try to do it in the sequence.

And so if you use the page as an example, the Thesis hook, what happens here is that the page starts rendering from top to bottom. So the very first Thesis hook to fire is Thesis hook before HTML. And then the next hook to fire is Thesis hook before header and so on and so forth. And so if you want something to happen at Thesis hook before header, that’s the hook that you use so that’s what we did in this. We knew that the nav menu was hooked to Thesis hook before header so we use that hook to remove it. And we knew that we wanted it to place it after the header so we used the Thesis hook after header to add it.

Jared: So a hook makes the bus stop appear or not appear?

Rick: The hook is the bus stop. The add action makes the bus stop but the hook is the actual bus stop. And you either drive right on by because there’s nothing to do or you stop there and do something.

The Thesis Open Hook Plugin

Rick: Let’s see, I think I have a couple other questions. How does this relate to the Thesis Open Hook plugin?

The Thesis Open Hook plugin is a rudimentary way of acting on Thesis hooks. So rather than saying add action or remove action, you would place your code there. Now somebody taking this class isn’t going to use Open Hook because really, using Open Hook is more complicated than this.

The add action name of the hook, name of the function, I think is easier to do than to figure out how to use Open Hook. But essentially, every place in Open Hook is an add action and it’s an add action at a specific hook. And then you put something in that box and that is the thing that happens at that hook.

Add a Privacy Policy Link in the Footer without using a Widget

Rick: Let’s see, she did ask the question how to put a privacy policy link in the bottom without using a widget. And the answer to that question is essentially the same way we did this other thing. If you have a link to a page, you can easily just come down here and add another p tag and then closing p tag. And then we put a new a tag inside of that so a href equals and I’m just going to pick a page.

Let’s just say that demo 7 is my privacy policy so I’m going to copy that there. And then once I have the URL, I can just paste the URL in there. So this and then give it a title, “Read our Privacy Policy.” And then use the anchor tag which should be, say read our privacy policy.

Okay so now what we have is a new paragraph with a link to our privacy policy. And if we hit save and we go back to Customize Thesis Like A Pro Lesson 9. And wp content, themes, thesis 184, custom, custom functions php and go over to the page and refresh it. Now we should have a link to our privacy policy at the bottom of this. Our privacy policy takes us to that very page. Click back over here and hit our privacy policy. It takes us to the page we selected for that.

Create a Responsive Child Theme for Thesis Class

So we are starting a class next Thursday on how to create a responsive child theme for Thesis and one of the reasons why I did this lesson is because I wanted people to have this as a reference, because that class is going to be very focused on writing php.

But it’s still intended for somebody who is comfortable with the material that we’ve presented here today. So we should have this up by the first part of next part of next week ready for people to watch.

So thank you very much everybody for joining me. I enjoyed it very much. I hope you got a benefit out of it and I look forward to talking with all the rest of you again soon. Bye bye.

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