2

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:

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

1

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.

7
  • Indeed it is a theme that will be managed only by our company, so even if there are 3 devs working on it, it is not very hard. On the contrary - I believe it is simpler. Also, the theme is used as a custom theme for a project and won't be sold or distributed in any way. We would also use it for other project that are very custom-oriented.
    – trainoasis
    May 11, 2016 at 11:11
  • 1
    "by our company" != "by you". The next developer that will have to work on the theme once you move on is likely to learn wordpress from the freely available resource and not from your badly documented hack (you, me and everyone else in the same boat here, no one is doing enough documenting on his own code). It is just so much simpler to follow conventions where at least you can ask for help, which is much harder when you do things your way May 11, 2016 at 11:35
  • Ok, I guess I agree, thanks. Will probably have to try a different CMS/framework with more tendency towards MVC principles sometime soon :)
    – trainoasis
    May 11, 2016 at 11:41
  • 1
    Not really,as you will have to write the code to do that and said developer will have to waste an hour of his time (if he is competent enough) to figure things out. The average quality of wordpress developers (developer is such a fuzzy word in wordpress world) is relatively low and they know how to copy & paste code and do some small modifications but will not know how to start investigating anything unusual. If you are going to hire people that use symphony/laravel etc they might not have problems with such mod, but the low cost WP developers might have a hard time. May 11, 2016 at 12:13
  • 1
    Perhaps an hour of a competent developer's time is a good thing - if he can save plenty of hours later with better organisation for the given project? Perhaps it's a good test at least to reject low quality developers? :D Ok, I'm going to stop - I see where you are going with this and perhaps I really should leave things as they are.
    – trainoasis
    May 12, 2016 at 6:19
1

I agree with Mark that it's not the best idea i've ever heard of, but it is easily done, by defering everything to index.php. Start that file as follows:

if (is_404() and file_exists (get_template_directory() . '/wp_template_parts/404.php')
    {get_template_part (get_template_directory() . '/wp_template_parts/404.php');}
elseif (is_page() ... and so on
...
else { normal index.php loop; }

Make sure to take the Wordpress Hierarchy into account when putting your if-elses in order. If you want different page templates (like page-singlecolumn.php) there is the additional problem that WP will not find them automatically, because it is looking for them in the root. You would have to write to the database to make different templates available when editing pages.

Basically, this means you must take care yourself of stuff WP would do for you if you did it their way.

1

Your Answer

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

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