theme development - Can I have two files with same name but different directory?

I'm developing a theme where home page is organized in sections & made template parts for each one of them. lik

I'm developing a theme where home page is organized in sections & made template parts for each one of them. like: hero-home.php, featured-home.php

Now the customizer settings for those sections are also organized in parts & have the same name like hero-home.php, featured-home.php etc....

But the directories are different for the files.

Now is this permitted? bad practice? or my theme will get reject from wordpress if I do it like this way?

*** English is not my first language..

I'm developing a theme where home page is organized in sections & made template parts for each one of them. like: hero-home.php, featured-home.php

Now the customizer settings for those sections are also organized in parts & have the same name like hero-home.php, featured-home.php etc....

But the directories are different for the files.

Now is this permitted? bad practice? or my theme will get reject from wordpress if I do it like this way?

*** English is not my first language..

Share Improve this question asked May 9, 2019 at 6:55 Aohor ArsalanAohor Arsalan 32 bronze badges 1
  • you can have same file name for templates in different directories, but actual template name should be different – Vishwa Commented May 9, 2019 at 6:59
Add a comment  | 

1 Answer 1

Reset to default 0

No matter from which perspective you consider it, it is bad practice to name files the same. To answer your question: Yes, you can do it this way, which doesn't mean that you should it this way. Even you, the developer of the theme, will get confused (I bet some beer or coffee if you want) from time to time when you are not aware of the current file which you are editing.

Your theme will propably not get rejected if the things works a 100%. However, you should stick to WordPress' mentality: code is poetry.

There are lots of options you have, for example:

  • you could prefix (for example: tpl-home.php, etc.) the template files instead of naming them the same.
  • you could name them differently
  • put them in a folder called "template-parts" or something similar

It is recommended to stick to your internal code convention in terms of structure. That way somebody who has downloaded your theme will faster be able to modify it to their needs. Because they don't need to go to university in advance to understand your logic. (you get the idea).

That, in return, will make your theme users happy because they can achieve their goals in terms of layout etc.. Make sure correct translations and child theming is supported/works.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745510778a4630761.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信