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
My Site▼
+ New
Howdy, Admin
Dashboard
Posts
Books
All Books
Add New
Categories
Media
Pages
Books
All (1) |Published (1)
Title
Date
Example Book Item
Edit | Trash | View
Published
2024/10/24
2024/10/24
How to use this
- Configure your Post Type options on the left.
- Switch to the Generated PHP tab.
- Copy the code and paste it into your theme's
functions.phpor a custom plugin. - 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/.