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.

So in my index.php I called get_header(), get_sidebar() and get_footer(). My index.php is kind of huge. It is separated into 5 divs more. How do I make it cleaner? Is it safe to chop it to files and include the files?

share|improve this question
1  
why don't you just give it "a chop" first? –  Jesse Apr 24 '13 at 3:47

1 Answer 1

Yes, you can separate your code and markup into multiple files. Be aware of scope issues when you use include, but done carefully it should be no problem. Since you are in WordPress and building a theme, I would suggest get_template_part over a raw include.

In many ways, "chopping" up your theme files is what get_template_part is for-- well, at least it is very convenient for that. It lets you separate components of the page and include them in a way that makes easy to extend via child themes.

share|improve this answer
    
Good to know that get_template_part is using require not include. –  Zlatev Apr 24 '13 at 10:54
    
@Zlatev : the question asked about include so I talked about include. Yes, get_template_part uses locate_template which uses load_template which does use require, or require_once. Given that locate_template locates the file before trying to load the file I don't see the significant difference between the two in context. require will kill the script, include won't, but given that the function never runs unless the file is located it doesn't really matter. You can get_template_part('nonexistent','template'); all you want and the script just skips right over it. –  s_ha_dum Apr 24 '13 at 13:38
    
Of course. I simply wanted to clarify what QA can expect using get_template_part as included files won't inherit variables for example. –  Zlatev Apr 24 '13 at 19:49

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.