Theme folder needs cleaning, now!

Published: On Saturday, July 28, 2007

More practically oriented sequel of Theme folder needs cleaning, right? article, in which I talked about the mess in default theme folder, but only theoretically. We, theme developers, do not have to wait until WordPress developers make changes in Kubrick, which often serves us as a model and this is a really bad habit, but some modifications are able to be done long since.

Group styles together

If you need to have more than only one file with CSS code, it's proper to store these files beside each other. For example I usually need three CSS files: standard visual, visual for IE6 (linked in HTML via conditional comments) and one for printers.

  • style.css
  • style.ie.css
  • style.print.css

Even if I don't sort theme folder anyway, what means files are sorted alphabetically, these guys are always together.

This same principle (adding identical prefix to all files in group) we can apply in more cases.

Grouping some code blocks

Except page templates, where filename doesn't ever matter, we are able to group some another code-blocks together.

  • header
  • footer
  • sidebar(s)
  • search-form
  • (…)

(I will call these file bordering code blocks because I can't come up with anything better now.)

But it must be remembered, that after changing default names of bordering code blocks the default functions for including these files stop working as well. get_header() will not include our renamed header anymore. At this moment, if WordPress won't find default.php in active-theme-folder, it will try to load header from default-theme folder. If we want to use renamed bordering code blocks, we must stop using functions…

  • get_header
  • get_footer
  • get_sidebar

… and start using the same syntax as is the search-form by default loaded:

include (TEMPLATEPATH . '/search-form.php');

One more thing should be remembered: if you want to add comments-block file to the previous group, you must change the calling of the comments_template() function to:

comments_template('/comments-renamed.php');

But it's unfortunately all, what we can do. All the files from 404.php to single.php must stay how they are so doing the last step in tiding-up procedure is impossible. Now ours theme's folder can look like this:

Update: It's unfortunately not possible to rename functions.php file, the screen lies in this.


Comments

Comments are closed.

I quit working with WordPress, comments are closed. My plugins will not be updated any more – at least not by me. Feel free to modify my source codes though… Also I am not able to provide support, sorry. –Kahi