Do i need to keep register_post_type in functions.php?

I am creating several custom post types, do I need to keep the register_post_type calls in functions.php? I would assume that this would only need to be run the once then removed, or do I need to keep the calls there?

Related posts

Leave a Reply

3 comments

  1. Yes, you need to keep it within functions.php and within the init hook, as it will have to register each time. It’s not like with roles, where you can add it once and it’s saved in the database.

  2. As PHP is stateless, CPT needs to be runs for each thread and its code needs to stay permanently.

    However, this leads me to the reason of my anser : instead of creating CPT in functions.php, best practice would be to create a plugin. The idea is if you need to change theme at some point, you will “loose” CPT ; so using a plugin allow you to have liberty of changing theme without loosing CPT data and admin UI.