1

I am trying to bring some order in to theme files and would like to separate templates parts. I see that underscore ( _s ) has done something similar enter image description here

but they moved only content templates inside ,

I have several templates for header , footer, content, portfolio,

do you think that order like this would be ok

theme_name/
-theme-templates/
    --headers/
    --- header-centered.php
    --- header-left.php
    --- header-right.php
    --- header-menubottom.php
    --footers/
    --- footer-grid.php
    --- footer-blank.php
    --content/
    --- content-single.php
    --- content-page.php
    --- content-none.php
    --- content-search.php
    --portfolio/
    --- portfolio-full.php
    --- portfolio-split.php

or would I run in to some trouble ?

Any help is appreciated.

1 Answer 1

1

Looking at the following source codes

you are going to have issues, more with your custom headers and footers. I do not know what portfolio is and how it will be used, so I cannot answers on that specific subject

get_footer() and get_header() does not allow for custom headers and footers to be loaded from a subfolder. Looking at the source codes, the only valid file names are as follow

  • For headers, it will be header-{$name}.php and header.php

  • For footers, it will be footer-{$name}.php and footer.php

There are no filters to adjust this behavior in get_footer() and get_header(). There is a hackish method that you can use here though. For this to work, you will need to name your folders as follow

  • For headers, you will need to name your folder header-{whatever}, where {whatever} can be anything you like

  • For footers, you will need to name your folder footer-{whatever}, where {whatever} can be anything you like

(Note: Using anything else than header and footer as prefix in the folder name will not work). You can then call your custom footers and headers in the following manner

get_header( 'whatever/header-centered' );

which create a filename like header-whatever/header-centered.php

As for template parts, I cannot see any issues right of the back. All you need to remember is to add the subfolder name as part of $slug

Instead of

get_template_part( 'content', 'single' );

you will need to do the following if your subfolder is called content

get_template_part( 'content/content', 'single' );
2
  • thnx for the info , get_header and get_footer are used as default without any funky biz, I was mostly concerned about get_template_part and yes , I did change the paths so all is nice and tidy now.
    – Benn
    Feb 3, 2016 at 12:30
  • For the header and footer, instead of the hackish method you can ignore the get_header() method and use get_template_part() along with do_action('get_header'). Example here: stackoverflow.com/a/35687331/211786 Feb 28, 2016 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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