They should be registered on the init-hook ideally (according to the documentation: Registering custom post types.

However, I'm trying to use this boilerplate here: WordPress Plugin Boilerplate, since it seems to have a good thought and layout.

But I'm not sure where in that plugin, to add the registering of new post types?

There is a function: load_dependencies here - but is a custom post type a dependency? Hmm...


I can see that if I do this:

$this->loader->add_action( 'init', $this, 'temp' );

and add that here: includes/class-plugin-name.php -> load_dependencies

And add a function on line 128 like this:

    public function temp(){
        echo '<pre>';
        echo '</pre>';

Then it works.

However... I still don't see the proper place to add this code, in order to follow the plugin standards.

  • 1
    Note that if you are seeking the official WP Boilerplate plugins opinion, aka what Devin Vinson thinks you should do, then you will need to ask him, and only him. I've left an answer below but it's a general WordPress answer, not a WP Boilerplate answer. ( strictly speaking WP Boilerplate is offtopic here but I'm being generous with my interpretation of your question )
    – Tom J Nowell
    Mar 22, 2022 at 20:35

1 Answer 1


However... I still don't see the proper place to add this code, in order to follow the plugin standards.

There is no proper place, and there's no canonical correct answer here, only subjective opinions. The plugin standards do no give an answer for your question.

This boilerplate is just one starting point of many available, and there are lots and lots of options for what you should do, with tradeoffs of their own, or just personal preferences.

The boilerplates folder structure implies a file in the includes folder would do the trick, but you could put it in a subfolder, or an existing file, or a new file, it could be a function, a class, or you could have a separate folder alongside includes called php that has it in there, there's no right or wrong answer.

Plugin standards say this about the structure of a plugin:

  • It must be a PHP file with a comment at the top containing Plugin Name:
  • That comment can contain other items as well, but it must contain the plugins name, and it must be within the first XX bytes of the file
  • That file can be in the plugins folder, or, in a subfolder
  • That file will be loaded if activated before the theme/query, but after WordPress itself

And that's it. Your plugin can be structured in any way you want. It can be a function and hook in a standalone file, or it could be a Symfony application with a custom entry point and hundreds of classes and folders. Neither is more correct than the other.

  • it's clear from the boilerplate that its author likes class oriented coding ( despite claims, this is not an object oriented codebase ), but does that mean you need to extend a class to add a class function? Modify an existing class function? Add a new class? Modify an existing class? Yes! And No! And both! And neither! And all of the above!
    – Tom J Nowell
    Mar 22, 2022 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.