WordPress.org

Ready to get started?Download WordPress

Forums

Where does Custom Post Type registration need to be placed in functions.php? (5 posts)

  1. PARoss
    Member
    Posted 4 years ago #

    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?

  2. Spencer Finnell
    Member
    Posted 4 years ago #

    You can put it anywhere. It doesn't matter.

  3. PARoss
    Member
    Posted 4 years ago #

    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.

  4. Spencer Finnell
    Member
    Posted 4 years ago #

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

  5. danorton
    Member
    Posted 4 years ago #

    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);
    }

Topic Closed

This topic has been closed to new replies.

About this Topic