Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on something these days I do not know if it's good practise. My plugin has to take some templates and put them into theme instead of existing header.php and footer.php.

EDIT2 : Not a good idea in fact, pretty uncool :/

EDIT3 : Last EDIT was sick, I guess I'm fed up with this work. Nevertheless I'm pretty stunned WordPress does not allow to include some code in template. Is it for security reasons?

share|improve this question
    
What are other contents? –  Sisir Sep 18 '13 at 13:22
    
main content, sidebar and widgets, etc –  JMau Sep 18 '13 at 13:26
    
What is in your header and footer file? Just looking at the file names, you aren't loading anything but the header and footer. –  s_ha_dum Sep 18 '13 at 13:34
    
is WP_DEBUG on? also I think template redirect isn't the right hook for this. including them will print header.php and footer.php early (before html starts). –  Sisir Sep 18 '13 at 13:36
    
WP_DEBUGis always on –  JMau Sep 18 '13 at 13:43
show 2 more comments

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
If it was just me I would have set up a child theme or something else but I do not have control on it. I have to include some code. –  JMau Sep 18 '13 at 14:46
    
Sorry, what you are doing sounds fundamentally flawed to me both in theory and practice... maybe if you explained why you need to do this... –  s_ha_dum Sep 18 '13 at 14:48
    
I've Edited again. I need to include some scripts and stuffs like img in header and footer. I guess I'm doing wrong like you said but the theme is so poor (multiple notices, bugs etc) –  JMau Sep 18 '13 at 15:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.