0

I'm creating my first Wordpress theme and I learned about custom post types. They sounded great for different reasons and I really wanted to implement them. But I read somewhere that when the user of the theme changes to another theme that doesn't support that post type, they'll literally lose the ability to see all their custom posts.

I don't want this to happen, so I'm thinking of other approaches like

  • Telling the users to create categories and loop the to get posts from the category
  • Creating custom taxonomies.

At this point, I need your help because you have experience creating these classes of post types. What could I do and why?

4
  • When you intend to extend the functionality (e.g. by adding new post type) you should create a plugin. This way, additional functionality will be available as long as the plugin is active, regardless of the selected theme.
    – nmr
    Commented Apr 25, 2019 at 14:04
  • Thank you friend. So in essence, I should create plugins for every theme I make? Commented Apr 25, 2019 at 14:10
  • 1
    Only if you need to add functionality which would otherwise break if you changed theme. Commented Apr 25, 2019 at 14:22
  • 1
    If something is not related only to your theme, you should think about moving it to the plugin.
    – nmr
    Commented Apr 25, 2019 at 14:27

2 Answers 2

1

You've highlighted the issue of creating custom post types in a theme rather than in a plugin. If the user changes to a new theme then you cannot rely on any functionality in the theme you have created.

Themes can add functionality, but in general should be concerned with the presentation of your site

Plugins will add functionality

Hence this is where I suggest you add the register_post_type code. The Registering Custom Post Types documentation recommends this approach as well, so have a good read through that for more detail.

2
  • Alright. Thanks again Alex. I've gone through the docs and what I've learned is to include plugins for functionalities beyond presentation. Users can still use these plugins when they change themes. Another thing Alex, I've also read about child themes, would they be appropriate in this case? Commented Apr 25, 2019 at 14:41
  • A child theme allows users of your theme to override and extend the main theme (which would then be called the parent theme) so it's unrelated in this case of custom posts. Again, more details in the documentation for your reading pleasure! Commented Apr 25, 2019 at 14:51
1

What you've heard is correct. If you have developed specialized views of your custom post type (archive pages, single pages, categories, or setup custom queries for your post type ) and a user changes themes all those views are lost.

It's true, as has been mentioned, that the Custom Post Type should be created in a plugin, but the presentation of that cpt is created in the theme.

The real question, is once you've put time and energy into a creating a look and feel of your site, why would you let a user change the theme? You have created a design: stay with it. The reality is that more than just the custom post presentation will be lost if you change themes. The presentation of your blog goes too. Your colors, your fonts, your layout all are gone and back to what ever the new themes settings are.

Now when the theme is changed, your pages, posts, AND cpt will still be displayed (because you created the CPT in a plugin) but they will be presented in a fashion that the new theme designer created. Since that designer was not thinking about your cpt wordpress will just treat your posts as default blog posts.

Think about it though, if you give a user the ability to change themes, then they likely can change your plugins too.

TLDR: Choose a theme and stick with it(don't change it unless there is a good reason). Create your CPT. Do it in a plugin.

2
  • Wow. This makes sense Rudtek. Thanks for the detailed information. You say something that makes me laugh anyway "The real question, is once you've put time and energy into a creating a look and feel of your site, why would you let a user change the theme?" If a user didn't change their previous theme, how would they install mine? Haha Commented Apr 25, 2019 at 14:47
  • Ah. Sorry for that part. I didn't know you were making it for others. I read it as you were making the theme for a specific site..
    – rudtek
    Commented Apr 25, 2019 at 18:16

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.