Once you’ve got your head around basic custom functions, you’ll probably run into code that uses the same hook and need to add a third parameter to your own custom functions.
Lets take a look at a very simple example:
- The first parameter is the hook –
genesis_after_header
- The second parameter is the custom function –
after_header_content
As you can see, this code above hooks into the genesis_after_header
hook and displays the text between the div tags.
The only problem is, by default in some themes, Genesis displays the primary nav menu in exactly the same position or hook location.
So basically speaking, the code executes and displays the content after the hook location as there’s another function using the same hook.
How do we fix this?
We simple add a third parameter to the code to include a priority number.
Considering the fact the default priority is 10, you won’t need to add a number which is higher than that if we want to display the content after the primary nav menu. The reason for this is the functions in the parent theme execute first and any other functions using the same hook execute after meaning they display after the default hook location.
Or
You’ll need to add a priority number as the 3rd parameter which is lower than 10 if you want the content to display before the primary nav menu using the same hook, genesis_after_header
.
Let’s go over the 3 parameters again:
genesis_after_header', 'before_primary_nav_menu', 8
- The first parameter is the hook –
genesis_after_header
- The second parameter is the custom function –
before_primary_nav_menu
- The third parameter is the priority number –
8
So you can see from these 3 examples which all execute using the genesis_after_header
hook that adding a 3rd priority determines when the custom function executes resulting in which position the content displays. Before or after the default hook location.
Position In Functions File
What if you have more than one custom function in your child themes functions all using the same hook?
If your functions don’t contain a third parameter for the priority, the execution position on the same hook is determined by the position the custom functions are placed in your functions file.
So the higher they are in the file determines the position they execute on the same hook.
Clearly this is overridden by adding a third parameter to the action and any default functions in the parent themes functions.php file.
Was This Tutorial Helpful?