Old question, but maybe my answer will help someone.
Short answer is:
use load_template()
function with full file server path as first argument passed to it.
Long answer:
get_header()
using the function locate_template()
which uses the function load_template()
which uses the function require_once()
. Thus, to load the header layout from a plugin or any other directory, you can directly use require_once()
and this will be completely correct if global variables like $post
and $wp_query
are not needed, otherwise case, use the load_template()
function passing the full server path to the file as the first argument.
P.S.
For more certainty, you can look at the files wp-includes/general-template.php
and wp-includes/template.php
, which contain all these functions. And you will see that there is no complicated logic in them, everything is very simple.
The only reason it’s better to use standard features is support. Support for the development of WP code lies on the shoulders of the team of developers, and your own functions are on yours.
But in this case, when you need to require your own header
file – this may be a justifiable solution.