Description
Hooks allow you to add extra functionality at various areas inside the theme. For example, you might want to display some promotional message below all of your blog posts. Hooks make such dynamic things possible.
Astra uses WordPress Hooks API to insert various hooks throughout the theme.
Usage
add_action( 'hook_name','callback_function_name' );
function callback_function_name () { ?>
// Insert your hook contents in here.
<?php }
In the example above, replace hook_name with the name of the hook you』re wanting to use, like astra_header_before or astra_header_after. Then replace callback_function_name with a unique meaningful function name, something specific to you.
To see the list of hooks available in Astra Visually, check out this site we』ve set.
Example
The astra_header_before hook is executed right before the Site Header.
Note: Site Header –
Add PHP to your header
// Add scripts to astra_header_before()
add_action( 'astra_header_before', 'add_script_before_header' );
function add_script_before_header() {
// Your PHP goes here
}
or…
Add HTML to your header
// Add content to astra_header_before()
add_action( 'astra_header_before', 'add_content_before_header' );
function add_content_before_header() { ?>
<?php }
If you are adding PHP to astra_header_before(), use the first method. Use the second method for anything else you may be adding.
Check out the doc that explains how to add custom PHP code using the child theme』s functions.php file.