1

I have created a custom post type called customtype. From my understanding the template file for it would be single-customtype.php which is placed inside wp-content/themes/mytheme.

Can I place the single-customtype.php file inside a custom folder in the theme directory? It's not critical but would help with theme files organization.

This is what I want to achieve: wp-content/themes/mytheme/customtype/single-customtype.php

  • 2
    I don't think this is going to be easy to do - you're essentially rewriting a part of WP's template architecture. I think these files would have to remain in your theme root, but as an answer states, you can use get_template_part() to split reusable bits of code up, including into subfolders. – Tim Malone May 2 '16 at 21:43
  • You can do it, but it's questionable as to whether it's worthwhile. Have a look at my answer to a similar question yesterday: wordpress.stackexchange.com/questions/227006/… If you're up for the challenge when you've seen that, I can help you modify that answer for your case. – Andy Macaulay-Brook May 19 '16 at 14:01
2

You may want to look at the TwentySixteen theme, which does it this way:

In single.php:

get_template_part( 'template-parts/content', 'single' );

Several templates are grouped in the 'template-parts' folder. You could use a similar logic for your custom post type.

It seems that the technique comes from _underscores.

  • single-customtype.php will still remain in the main directory (I was hoping to move archive-customtype.php as well) I'm more concerned about the main files than template parts but this will help a bit. – Aziz May 2 '16 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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