How to Use Hooks in Astra?

No results found. Try again with different words?

Search must be at least 3 characters.

Using Hooks in Astra


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.


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.


The astra_header_before hook is executed right before the Site Header.

Note: Site Header – <header id=”masthead”>.

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


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() { ?>
      <!-- Your HTML goes here -->
<?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. 

Was this article helpful?
Did not find a solution? We are here to help you succeed.

Related Docs

Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form