Example of a theme organization without all the default wp files in root

I know I can get rid of some of the default WP theme files required using get_template_part() for instance. But some files still need to be present – for instance, how would I move page.php to a subfolder so it still works? I am also aware, that you can put you own page templates to a custom folder and they are being recognised normally.

I’m aware, that changing WP core hierarchy structure is probably not the best idea, but for developing specific pages (non-blog oriented) it just might be. I don’t see how having many files in theme root is a good thing when you are trying to easily add a feature.

I know there are some similar questions out here, but none pointed to actual examples. Here are some:

  • How do i structure my theme folder to avoid one huge list of files
  • Can I put my WordPress theme files in another folder?

But can someone show an example of how to organise theme folder so that I would end up only with (roughly)

- mytheme
  -- functions
  -- img
  -- js
  -- styles
  -- languages
  -- custom-templates
     --- template-demo.php
     --- ...
  -- wp_template_parts 
     --- loop.php
     --- pagination.php
     --- comments.php
     --- header.php
     --- footer.php
     --- sidebar.php
     --- ...
  -- wp_default_view_templates 
     --- page.php
     --- single.php
     --- 404.php
     --- search.php
     --- archive.php
     --- ...
  -- index.php
  -- functions.php 
  -- style.css

where (for example) wp_default_view_templates folder consists of only WP default hierarchy templates.

Folder wp_template_parts includes default WP partials used multiple times.
(this already works via get_template_part())

views folder would include my custom page templates such as template-customstuff.php etc.

I have functions and assets such as css/js managed all right now. The only thing bothering me still are all the WP files in the root of the theme.

Is this reorganisation really such a bad idea?

2 Answers
2

Yes it is a bad idea. There are de facto standards on code organization in themes, and no one likes to figure out the code of someone else that thought that he is smarter than all WP developers before him, even if it is possible code wise to do it differently.

So unless you are planning to be the only one ever that works on that theme, please follow conventions and try to avoid inventing new ones.

Leave a Comment