I’ve few questions about the custom post type in WordPress.
a) I read that custom post type code should be embedded in a plugin. Is that really necessary?
b) Is the declaration add_action( 'init', 'create_post_type' );
supposed to stay forever, or once added for the first time can be later removed?
c) How can I programmatically add the content and associate it to my custom post type?
Thanks.
a) Try to imagine the moment of changing themes, do you really want to move all this functionality from one theme
functions
file to another? And repeat this at every theme change?See Where to put my code: plugin or functions.php?
b) Yes, it must run at every
init
. There’s no problem with that.c) This is way too broad, but you can start a research here and at WordPress Development with the function
wp_insert_post()
.