From the course: PHP for WordPress

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

What are functions?

What are functions?

- [Instructor] Functions play an incredibly important role in PHP and WordPress, and you've seen them, but we haven't defined them yet. So let's go ahead and do that now. Functions are reusable snippets of code that could be used multiple times. You can imagine functions like variables for lines or blocks of code, and there are two types of functions. The ones that you write yourself or the ones that come built in to PHP. We will look at both. But first, let's look at the structure of a function. You could see the syntax of a function on the screen here. We have the keyword function, which tells PHP that we are writing a function. Then we have the name of the function. Writing the name of a function follows the same conventions as writing the name of a variable, where we have each word in all lowercase and any spaces are replaced with underscores. We have parentheses, which we'll learn about later. And then we have the opening curly brace, some code, and the closing curly brace. In…

Contents