In this post we’ll review how to write a PHP function and go over the basic idea of how you can use Action Hooks in your WordPress Theme. We’ll take a look at a practical example of injecting a Welcome Blurb into your Theme without touching the existing code and we’ll also look at how to remove existing content being injected into Theme Hooks.
Packing Up A Function
Action hooks are in a lot of WordPress Themes nowadays. There’s a good reason for that but you’re probably wondering what the big deal is right? They’re such a big deal because firstly, they’re incredibly easy to use and secondly, because they’re extremely powerful.
If you want to get started with them we’re going to have to take a look at how to write a PHP function again. Don’t worry, we’ll keep it pretty simple.
So that’s how you write a PHP function. It’s pretty easy. It’s a little package of “stuff” like more PHP or HTML that you can write in 1 place—like your
functions.php file—and call in another place like so:
You’ve seen the same thing before with WordPress functions like
the_content(). These functions are packed with “stuff” deep in the bowels of the WordPress core and output wherever they appear in your template files.