Add code to template dynamically

Your code doesn’t just replace the header and footer file, it loads new header and footer files and dies. You are completely replacing the entire theme when you do this. Anything else you want to load, you need to load yourself. To load content, you are also going to have to provide a Loop, load the sidebars, essentially recreate the theme. You can’t just replace the header and footer, not like this.

Even if you got this to work and you did manage to just replace header.php and footer.php you are almost guaranteed to break whatever theme you are using since the header and footer both contain markup and are pretty much always different from theme to theme.

I can’t imagine how this is ever going to work correctly, unless, as I said you write everything into your callback– Loop, sidebars, etc. But that won’t match the rest of the theme.

I don’t like to give “you can’t do that” answers but I can’t work how this won’t make a mess even if you get it to work, so maybe this is a “please don’t do this” answer.

Both get_header and get_footer have corresponding hooks. Perhaps you can use those to do what you want.

By the way, I have seen plugins do something like this, but typically the plugin loads the theme header and footer and its own content block– backwards from what you are doing.