Site logo

Archived topic

Using generate_before_header hook to pull a global navigation php file

3 replies · Started by Michael on August 17, 2020

Viewing posts 1–4 of 4

We have a multisite install that requires a global navigation to display at the top of all of our child sites of our multisite install (above the header). I've made sure that the global_nav.php file is located in an inc directory located within the child theme folder. In the functions.php file I've tried to include the global navigation using the following:

/* Include global navigation*/
add_action( 'generate_before_header','global_nav' );
function global_nav() { ?>
	include_once ( get_stylesheet_directory() . '/inc/global_nav.php' );
<?php }

The hook seems to work but just displays the following code and not the menu:

include_once( get_stylesheet_directory() . '/inc/global_nav.php' );

I'm sure its something simple I'm missing but I just don't see it.

Hi there,

You've closed PHP, so it's rendering your PHP as regular text.

Try this:

/* Include global navigation*/
add_action( 'generate_before_header','global_nav' );
function global_nav() {
	include_once ( get_stylesheet_directory() . '/inc/global_nav.php' );
}

Dang. Thanks Tom! Much appreciated.

No problem! :)

This archived topic is closed to new replies.