Avada Hooks: Actions and Filters
Actions and Filters are provided by WordPress to allow your plugin to ‘hook into’ the rest of WordPress; the same concept is used by Avada to allow hooking into Avada specific functionality so that you can modify it in a child theme or even a plugin.
How To Use a Hook Or A Filter?
So, let’s assume you want to add a banner ad before the entire header. There are three ways to do that:
1. Edit the parent theme’s code and add the code in the header file
2. Copy the header file into the child theme and modify the code in that file
3. Use an action in a child theme’s functions.php
With the #1 and #2 above, there is a high possibility that the edit would be lost during an update. By using an action, you don’t edit or overwrite the core code which is why, your code will rarely need to be changed.
To add a banner ad before the entire header, we need to use the “avada_before_header_wrapper” action in the functions.php of the child theme. Following is an example code:
Filters are similar to the actions but instead of ‘hooking’ into the code, you are simply changing the final output. You can read more about the difference difference between actions and filters from the beginner’s guide.
How To Add Code After The Opening Body Tag
To add code, such as GTM script, after the opening
tag, you will have to use the “avada_before_body_content” filter. If you’re not familiar with editing child theme files or you don’t have a child theme installed, you can install the Code Snippets plugin then add this code to it:
Conversion For Child Themes
If you’d like to learn how to convert Child Themes and your own Custom Post Types, please click here and follow the instructions in the article.