Build Your Own Business Website header image

The Most Basic WordPress PHP Functions

Difficulty Level -

Filed Under Topics - ,

Listed Under Lesson Subjects -

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

We open the custom_functions.php file and go through two of the most basic WordPress PHP functions, add_action and remove_action. We use the example of removing our Thesis Nav Menu from it’s out of the box location above the header and add it back below the Header. We also discuss the what the custom.css file and custom_functions.php file are used for.

Video Transcript

Rick: I’m going to now do the next thing you asked for which is… the next thing you asked for was for me to show you how to you know, just go through the process step-by-step of taking that header… the menu and putting it below the header, right? So that’s what I’m going to do next.

Jared: Okay.

Rick: Okay and so, I’m going to take control back over if I can see how to do that… change presenter…there it is. Okay, show my screen. So the way we’re going to… what we’re going to do here, let’s see. Let’s figure out which site we’re working on first actually. I think we’re going to start with, let’s see… www.forumdemos.com. Let’s try that one, see where the…okay yeah, okay. So that’s got the menu above the header and that code that we just wrote, that would affect this thing right here: Rick’s Forum Demonstration. That’s your site title and that code would have styled this title right here. David asks whether or not we need to set up a dummy project and to be sure we can, just like I’d show in other videos, we can set up a dummy project simply by going to new project. We’re going to make it a PHP application so we’ll say next. The project name, I’m just going to call dummy project. Say next to that, we’re not going to worry about the URL at the moment because we’re not setting this up with a server. We’re not going to use either of those PHP frameworks. We’re just going to say finish and now, the project navigator shows up although as I’ve said before, we’re not really doing a project so these things aren’t particularly important. However, to the extent that you wanted to create a new file, you needed to have a project, a dummy project set up.

So okay but I’m going to close that now and what I’m going to do is open up the forum demo’s custom functions php file, so open file… let’s see. BYOB tutorial site is actually here. Forum demos, thesis_18, custom, custom functions php. Okay and so, in our custom functions php, what we’re going to do is the very first thing… I’m just going to start up here at the top. I’m outside of the comment block and I’m going to start off with the remove action. So it’s remove… oops, pardon me. Remove_action and then we enter the hook that we’re removing so it’s Thesis hook before header and then comma space single quotes and then it’s Thesis nav menu. And then we have to close out this function with a semi-colon so now, we’ve removed the Thesis nav menu and in fact, if we just stop right there and we save it, open up Filezilla… let’s see, forum demos and themes and thesis_18 and custom… and upload custom functions php then what we’re going to see on that site is now this thing should go away. There it is. So now, it’s gone and now what we have to do is add it to the underside of the header. So we go back here and so that was remove action. Now, it’s going to be add action… Thesis hook after header and comma space single quotes and then Thesis nav menu.

Now, bear in mind that this is not what I consider to be a basic task. This is an intermediate task that is, it involves code and so, it’s… those of you who are you know, don’t want to really deal with code related stuff can just go ahead and ignore this. But this is really sort of the very first set of functions that we learned in the Customizing Thesis Like a Pro series. It’s the remove action and it’s the add action and these are WordPressphp functions. And so, what we’ve done is we have removed this Thesis function from this Thesis hook and then we have added this Thesis function to this Thesis hook. So we’re going to go ahead and save that and upload it and test it. And now, our menu is down below. So Jared, I’m going to turn your microphone back on here for a second. Jared, is that as helpful as you’d hoped it would be?

Jared: Can you hear me?

Rick: Yes.

Jared: Okay, yes. A few questions… when you opened up your file, you opened up this custom php that you had me open up too. What is the difference and why?

Rick: What is the difference between what?

Jared: Well, you had me open up 2 files: custom and custom php.

Rick: I had you open up custom css and custom functions php.

Jared: Custom php?

Rick: Well, it’s because I wasn’t making a CSS change. There are… you know, really there are 4 types of code that are used on a WordPress website generally and on a Thesis website in particular and that is, PHP, HTML, CSS, and Javascript. And the principal language that runs your WordPress site is PHP.

Jared: So that’s what we’re doing most of the editing.

Rick: What’s that?

Jared: That’s where we’re likely to do most of the editing?

Rick: No, it’s not where you’re going to do most of the editing but it’s the only place to edit PHP files. So if you’re going to use a PHP function and needs to go inside of a custom functions php file. If you are editing CSS then that has to go inside of the custom CSS file. CSS is a different code and a different syntax than PHP. And so, they don’t go together in the same file.

Jared: Okay. Why do you have 2 custom function php files open in the tab up above?

Rick: Well, because I have the original one that I opened up first which is the library one and then I have the next one that I opened up which is the site we just… oh, actually pardon me. This is… is this the library one? No, yeah. This is the library one, right. And this is the one that I just opened to demonstrate the simple action. It’s 2 different websites, right? This website is the Community Library Website that we’ve been working on. This website is my forum demos website. They each have their own custom function php file. And actually, if you’re working on multiple websites at the same time, it can be actually irritatingly confusing because the files still have to be named custom css, custom php. You can’t change those names so if you have… if you’re working on multiple websites at the same time and you have multiple custom functions php open at the same time, what I do is this… which is actually, you don’t see me having done it here because I didn’t do it in this but I usually actually delete all this comment up here and say what the file is really being used for. And maybe I don’t do that as often on these demonstration sites but for you know, in the real world, I use my own… I you know, I say at the top of this who I am, what site I’m using it on, what version it is, what date it was, and all the rest of that kind of stuff to help me keep track of it.

Jared: One more question. You showed remove and add, that’s two separate steps. And DIY Themes shows them as one step. Is there any reason for that?

Rick: No, DIY Themes doesn’t show them as one step. They’re 2 functions and there’s not any way to combine them.

Jared: So you have to do them separately.

Rick: Yeah, it’s not so much a step as it is a function. Remove action is a specific kind of function that does a specific thing. You don’t remove action and add action together. You call one function and then you call the next function.

Jared: Okay, that’s fine.

Rick: Okay. And now that you’ve got the sense of how NetBeans goes together and it’s nice and fast. I like that. You know, work your way through those introductory lessons on CSS. That’s where I’d start and start with the introductory lessons on CSS and once you work your way through that, you know, you’ll have a good sense of where the files are, how they’re structured…you know, what you start at, what you edit in CSS and what you edit in php.

Jared: Okay.

Rick: So, okay. Okay?

Jared: Okay.

Rick: Okay. So then let’s see, the next question… Pam actually offers a suggestion for understanding the difference between php and CSS. And she suggests that php makes things happen and CSS changes how things look and that’s I think, a fair observation especially in good design. A well designed bit of code will separate the code for the appearance and the code of the structure and the code of the function. And in our situation, the appearance is CSS, the structure is HTML, and the function is php so…

0 Comments… add one

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

Leave a Comment