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?
Leave a Reply
You must be logged in to post a comment.
Yes, you need to keep it within
functions.php
and within theinit
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.I do agree with @Simon, that you should consider to use your custom plugin – as it’s a best practise. It’s as easy as creating your functions.php.
What’s more, you should take in consideration a Must use plugin. Again, it’s not complicated and it provides the assurance your custom plugin containing your custom taxonomies and post types (hand coded) get’s loaded.
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.