From the course: WordPress: Action and Filter Hooks
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Understanding callback functions - WordPress Tutorial
From the course: WordPress: Action and Filter Hooks
Understanding callback functions
- [Instructor] In programming terms, a callback function is simply a function that gets passed as an argument to another function. You've already seen some basic examples of them in this course, but I wanted to specifically call them out. See what I did there? First, we'll look at add_action along with an example of it in use and then we'll turn our attention to add_filter. Here, we're looking at the syntax for using the add_action function. The first parameter here is the name of the hook, which is telling WordPress where to run. The second parameter is the call back that tells WordPress what to run when it reaches the hook. Let's look at an example. This is the pre_get_posts action hook, and it's used to modify the WordPress query. If we scroll down and find an example, I want to find this example called sbt_exclude_category. So we're passing in the query object, and then we've got some WordPress conditional statements…
Contents
-
-
-
-
(Locked)
Finding references and documentation3m 33s
-
(Locked)
Identifying available hooks and filters4m 14s
-
(Locked)
A look at load order and dependencies4m 19s
-
(Locked)
Understanding callback functions4m 44s
-
(Locked)
Using apply_filters3m 55s
-
(Locked)
Registering and executing hooks in JavaScript47s
-
(Locked)
-
-
-