Backend and Infrastructure

Using Require to Include Functions

Sprout Video

We want to update our contact page with the number of pets we currently have, which means we'll need to dynamically count our pets. We can use the get_pets() function to get us that information, but we're going to have to learn how to load the function from one file for use on another file. We're going to create a new home for our functions, in a functions.php file, to keep them centralized, and then we will use the require statement to use that file when we need it. We'll also discuss the other statement you can use in this instance—require_once, include, and include_once—and why we're choosing require over the others.

Additional resources

Tip: Why is not closing your PHP tags better when you don’t have to? Great question — see StackOverflow: Why would one omit the close tag?