From the course: WordPress: Action and Filter Hooks
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Adding custom hooks - WordPress Tutorial
From the course: WordPress: Action and Filter Hooks
Adding custom hooks
- [Instructor] We've looked at various hooks that WordPress provides, and we know that these are part of the plugin API that enable us to inject our own code into WordPress. If you're writing a plugin, you may choose to give other developers a way to interact with your code, and you could do that by creating your own hooks. Creating your own action and filter hooks is actually pretty straightforward. You use apply_filters to create a filter hook, and do_action to create an action hook. Let's look at an example of how to create a custom hook with both of these. Pretend you have a plugin, and we'll creatively name it Your Plugin, and it includes two functions: top and bottom. We echo the top function, which outputs, "This is the top," and then echo bottom, which prints, "This is the bottom." Now what if I have my plugin, again, super creatively named My Plugin, and I want to interact with your plugin? Maybe I want to do…