Support » Fixing WordPress » Where does Custom Post Type registration need to be placed in functions.php?

  • I’m trying to add A Custom Post Type, but the documentation does not say where in the functions.php code to add the registration code. I’ve tried a couple of places, but not luck. (Yep, I’m not a coder, but I can do snippets if I know where to put them.

    Where in the functions.php code does the Custom Post Types code go?

Viewing 4 replies - 1 through 4 (of 4 total)
  • You can put it anywhere. It doesn’t matter.

    Ah, but it does. I have tried it at the end of the file and it consistently doesn’t work. Don’t underestimate my ignorance.

    Do you get an error? Or does it just not work?

    The code can go anywhere in your functions.php, but the call to register_post_type() must not be before initialization, You can call it anytime during or after. For example, this won’t work:

    $args = array(...);
    register_post_type('mytype', $args);

    This should work fine (it does for me):

    add_action('init','my_create_post_types');
    function my_create_post_types() {
      $args = array(...);
      register_post_type('mytype', $args);
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Where does Custom Post Type registration need to be placed in functions.php?’ is closed to new replies.