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

Where to put code for coding Custom Post Types?

programmeradmin0浏览0评论

I’m wondering what is the best place to put the php code for defining custom post types.

Looks like theme functions.php is a big no-no because CPT are lost when switching theme

Wordpress codex recommends defining CPTs inside a plugin code

Some authors of tutorials I read recommend to define CPTs in a mu-plugin, which cannot be accidentally deactivated. That sounds like a great idea to me

Anyway, is there a wordpress (or Wordpress developer community) best practice?

Many thanks

I’m wondering what is the best place to put the php code for defining custom post types.

Looks like theme functions.php is a big no-no because CPT are lost when switching theme

Wordpress codex recommends defining CPTs inside a plugin code

Some authors of tutorials I read recommend to define CPTs in a mu-plugin, which cannot be accidentally deactivated. That sounds like a great idea to me

Anyway, is there a wordpress (or Wordpress developer community) best practice?

Many thanks

Share Improve this question edited Sep 22, 2019 at 8:07 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Sep 22, 2019 at 7:41 Guido BraslettiGuido Brasletti 1
Add a comment  | 

1 Answer 1

Reset to default -1

I think that this choice really depends on the project. If a post type is intrinsically linked to the theme. Maybe your theme will have a js and css bundle that includes post type features. In this case it is better to define it immediately in this one. But it really depends on the project and how the code is organized. There is no "THE right method".

But if the custom post type brings new features that may potentially need to be deleted (for example: an event list on a site). It is better to define them in a plugin or mu-plugin.

发布评论

评论列表(0)

  1. 暂无评论