This guide covers “custom post type in wordpress” in plain language. A custom post type is a content type you define yourself, such as Books, Properties, Recipes or Team Members. WordPress comes with posts and pages, but real sites often need more structure. This guide shows two ways to create a custom post type: with a plugin and with code.
Why use a custom post type?
- Separate content types. Keep portfolio items out of your blog feed.
- Cleaner admin. Each type gets its own menu and editor.
- Better templates. Display each type with its own layout.
- Flexible data. Pair types with custom fields and taxonomies for rich content like listings or directories.
Method 1: Use a plugin
The easiest route needs no code.
- Install a post type plugin, such as Custom Post Type UI, and activate it.
- Go to the plugin’s Add/Edit Post Types screen.
- Enter a slug (lowercase, no spaces, such as
book), plural and singular labels. - Choose options like public visibility, archive support and which editor features to include.
- Save, and a new menu item appears in your dashboard.
Plugins are friendly and let you change settings later without editing files.
Method 2: Use code
Adding the type in code keeps it in your site’s files. Put this in a small plugin or your child theme’s functions.php:
add_action( 'init', function () {
register_post_type( 'book', array(
'labels' => array(
'name' => 'Books',
'singular_name' => 'Book',
),
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'menu_icon' => 'dashicons-book',
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
'rewrite' => array( 'slug' => 'books' ),
) );
} );
Key options:
publicmakes the type visible on the front end and in the admin.has_archivecreates an archive page at/books/.show_in_restenables the block editor and REST API.supportslists which editor features appear.rewritesets the URL structure.
After adding the code, go to Settings, then Permalinks and click Save to refresh rewrite rules. Without this step you may see 404 errors.
Where should the code live?
If you put the code in your theme, your post types vanish when you change themes. For content you want to keep, a small custom plugin is safer.
Display your custom post type
- Archive page. With
has_archiveon, visit/books/to see a listing. - Single page. Each entry has its own URL.
- Custom templates. Create
single-book.phpandarchive-book.phpin your theme, or use a builder that supports custom templates and query loops. - Query on any page. Use
WP_Querywith'post_type' => 'book'to list entries anywhere.
Add custom fields and categories
Most useful post types need extra data, such as price, author or ISBN. Custom field tools like ACF handle this without code. You can also register a custom taxonomy, for example a Genre for Books, to group entries.
Common mistakes on your custom post type in wordpress
- Forgetting to flush permalinks after registering.
- Using a slug that is too long (WordPress limits post type keys to 20 characters).
- Using a slug that clashes with existing WordPress names.
- Putting the registration inside the theme when you want the content to outlive it.
Custom post type in WordPress FAQ
Will a custom post type slow my site?
No. A post type is just another content type stored in the same database table.
Can I turn existing posts into a custom post type?
Yes. Plugins and WP-CLI can change the type of existing entries. Back up first.
Do custom post types appear in search?
If public is true and exclude_from_search is false, they appear in site search.