最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论