I have a page.php
in which I am defining a custom sub-menu to pass to header.php
.
I've tried using a constant (clumsy, I know):
define("CUSTOM_MENU", "<ul><li>Test</li></ul>");
right after this, the code is including the header:
get_header();
In the header.php file, where the sub menu is, I am outputting either the custom sub-menu (if set), or a wp_nav_menu
:
if (defined("CUSTOM_MENU"))
echo constant("CUSTOM_MENU");
else
wp_nav_menu(array(some stuff));
bizarrely though, the CUSTOM_MENU
constant becomes empty the moment get_header()
gets called - and stays empty for the rest of page.php
:
define("CUSTOM_MENU", "<ul><li>Test</li></ul>");
echo constant("CUSTOM_MENU"); // The HTML code above
get_header();
echo constant("CUSTOM_MENU"); // Null!
This happens for any method of storing the custom menu data that I use. I have tried:
- Different constant names
- Namespaced constants
- Global variables
- A function with a static variable
I can't get my head around why this would happen! If get_header()
somehow was including header.php using the http wrapper, then the value wouldn't be unset once we exit get_header()
again.
What is going on here? Am I overlooking something obvious?
wp_nav_menu()
). Thepage-xxx.php
file for each page would be the ideal location for defining each menu... although I'm open to whatever method works!