WPDev.one
Live Preview
PHP 8.0+

Register Custom Post Type

Stop writing boilerplate. Configure your labels, capabilities, and Gutenberg support visually, then copy the production-ready PHP code.

Configuration

Find icons
My Site
+ New
Howdy, Admin

Books

All (1) |Published (1)
Title
Date
Example Book Item
Edit | Trash | View
Published
2024/10/24

How to use this

  1. Configure your Post Type options on the left.
  2. Switch to the Generated PHP tab.
  3. Copy the code and paste it into your theme's functions.php or a custom plugin.
  4. Go to Settings > Permalinks and click "Save Changes" to flush rewrite rules.

How to use this code

The code generated above hooks into init to register your content type with WordPress. You have two options for implementation:

A

Theme (functions.php)

Easiest for single-use. Paste the code at the bottom of your active theme's functions.php file.
Warning: You lose the post type if you switch themes.

B

Custom Plugin (Recommended)

Create a file in wp-content/plugins/my-cpt.php, add a plugin header, and paste the code there.
Best for portability and data safety.

Critical Settings Explained

Hierarchical
If set to True, your post type behaves like Pages (can have parents/children). If False, it behaves like Posts (organized by date/categories).
Show in REST
This MUST be True to use the Gutenberg Block Editor. If set to false, WordPress forces the Classic Editor.
Has Archive
Enables a public list page for your posts at your-site.com/post-type-slug/.