8

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?

1

4 Answers 4

19

In short, there is no well defined convention for naming a theme's directory, and all of the following are valid (among others):

  • my_wordpress_theme
  • my-wordpress-theme (empirically the most popular option within the ecosystem)
  • MyWordPressTheme
  • mywordpresstheme (what the default themes use)

Details

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 WordPress itself largely ignores the directory name for this purpose. 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.

2
  • 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
    Commented Mar 3, 2014 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!
    – bosco
    Commented Mar 3, 2014 at 19:43
3

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)

2
  • 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
    Commented Feb 28, 2014 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
    Commented Feb 28, 2014 at 3:20
0

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.

0

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

Your Answer

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

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