Bummer! This is just a preview. You need to be signed in with a Treehouse account to view the entire video.
The add_action Function1:23 with Zac Gordon
In this video we go over how to use the add_action function to hook your own functions into existing action hooks.
Since we already looked at add filter in the last section, it's going to
make a lot more sense beginning to look at add action, because its very similar.
We can see that it takes the hook that we want to hook into,
the function that we want to add, the priority, and the accepted arguments.
If we were to go back and look at add_filter,
we could see this is the exact same, except the word here, is just different.
If we take an example of add_action in practice, we could see could see us
tying into the very common action that you've probably seen before,
wp_enqueue_scripts, calling our own custom function.
And then inside of there enqueuing a Google style sheet from, Google Fonts.
So, when it's time for wp_enqueue_scripts to run or
execute in WordPress, it will simply call our function and output this out.
that where we had add_filter_example, we had to return a value.
In this, we're simply executing some code.
Remember the difference between filters and actions, is that filters manipulate or
change the data, then return it to WordPress.
Whereas actions just give us a place, to run our code
You need to sign up for Treehouse in order to download course files.Sign up