How do I create a custom post type in WordPress?

Reading Time: 2 minutes

TL;DR: Register it with register_post_type on the init hook, define labels and supports, set public and has_archive, give it a rewrite slug, then flush permalinks once by saving the settings screen.

Custom post types separate structured content from your blog, which is what makes a portfolio, solutions library or catalogue maintainable.

Step 1 Decide whether you need one

If the content has its own listing page, its own fields and its own taxonomy, it deserves a post type. If it is simply a blog article with a category, use posts. Creating post types for everything produces an admin nobody can navigate.

Step 2 Choose your registration method

Register via code in a small custom functionality plugin, or use a plugin such as CPT UI. Code is cleaner and portable; a UI plugin is faster and lets non-developers adjust labels.

Step 3 Keep registration out of your theme

Avoid putting registration code in your theme’s functions.php, because switching themes would orphan your content. A functionality plugin survives theme changes.

Step 4 Register on the init hook

Hook your function to init. Define singular and plural labels, set public to true, enable has_archive if you want a listing page, and specify supports for title, editor, thumbnail, excerpt and revisions as appropriate.

Step 5 Enable REST support

Set show_in_rest to true if you want the block editor and REST API access. Omitting this is a common reason a new post type unexpectedly gets the classic editor.

Step 6 Set a deliberate rewrite slug

The slug determines your URLs, so choose it for readability and SEO rather than accepting the internal name. Once indexed, changing it requires redirects, so decide carefully at the start.

Step 7 Attach taxonomies and flush rules once

Register custom taxonomies for the dimensions you will filter by and associate them with the post type. Then visit Settings then Permalinks and save to flush rewrite rules. Do not add flush calls to every page load, a common performance mistake in tutorials.

Step 8 Build the templates

Create archive and single templates following the template hierarchy, or use your builder’s theme-building features. Add the custom fields your content needs and confirm the editing experience is pleasant for whoever maintains it.

Back to How-To

Was this helpful?

Thanks for your feedback!

Comments are closed