Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm confused and I didn't find any answer by Googling. My theme files such as single.php or header.php reside in a folder. Should I use dashes or underscores in the folder name? My web server run on Linux / Apache and I'm not sure what the consequences are regarding folder names. So should I prefer something like

my_wordpress_theme_folder

over

my-wordpress-theme-folder

or are both equally valid?

share|improve this question

4 Answers 4

up vote 12 down vote accepted

The WordPress PHP Coding Standards Handbook states that filenames should be all lowercase and hyphen-separated. As Squish points out, various routines in the WordPress Template Hierarchy rely on this convention in order to auto-load templates for certain situations.

All of that said, you will not break Linux or Apache by using underscores instead of hyphens (though you will break conventionally loaded files in the template hierarchy). Directories don't seem to have any well-defined conventions, but as a rule of thumb avoid spaces in all of your names. Dots may or may not have undesired effects in directory names, particularly as *NIX conventions traditionally handle directories beginning with a dot as "hidden."

As the WP_Theme class's scandir() function makes direct use of PHP's scandir() followed by is_dir() in order to enumerate the individual themes in a directory rather than testing the naming conventions of entries, it shouldn't actually matter what your directories are named as it is the filesystem itself that marks a file as a directory. You can read the comments on the is_dir() page for some specific caveats. More than anything, ensure that your directory names work in URL-format and are navigable by a web-browser.

The themes packaged with WordPress use a directory naming convention of all lowercase letters and no punctuation, i.e. twentytwelve, twentythirteen, etc.

To answer your question in short, yes - both my_wordpress_theme_folder as well as my-wordpress-theme-folder are acceptable theme-directory naming schemes. MyWordPressThemeFolder would function equally as well, as would mywordpressthemefolder (which appears to be some unspoken standard of the WordPress devs themselves).

share|improve this answer
    
Thank you. I don't like cutting out all punctuation for 1) readability reasons and to a lesser extent 2) SEO reasons (dashes help Google recognize separate words). So I'll stick with dashes for file as well as and folder names. –  RubenGeert Mar 3 at 10:17
1  
I'm with you on the whole not-cutting-out-punctuation bit. Just always looks messy and creates miscommunication. CamelCasing things isn't much better as most web-servers consider the name interchangeable with it's all-lowercase counterpart by default. Good point about the SEO - I hadn't considered that before! –  boscho Mar 3 at 19:43

For directories it's personal preference (you can use spaces, too... not really recommended, though).

Wordpress convention seems to be dashes, though.

Especially because Wordpress does use dashes for special files.

For instance when you are making page templates, you can make a file called "page-special" and the template will load automatically for the page name "special". (e.g website.com/special)

share|improve this answer
    
Yeah, I'm aware of that. Not sure whether that holds for directory names as well. Just want to make sure there will be no undesired side effects if I do so... –  RubenGeert Feb 28 at 3:08
    
Stick with dashes, then. Unless you have a specific reason to do something else. It's just easier to stick with the established convention. If you want to experiment, though, be sure to use a local server. (I just tried to do a quick conversion of a theme's main directory and got a big ol' error.) –  Squish Feb 28 at 3:20

They're both valid for folder names. Most examples you will come across will have dashes, but I've found some generators use underscores because of issues with JavaScript and dashes.

That's also a generalization, since https://github.com/yeoman/generator-backbone/issues/2 sticks with dashes.

share|improve this answer

Well, You just can not leave space for the theme name but the following usages are correct....

"MyThemesName" "my-theme-name" "my_theme_name"

Thanks Sabbir

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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