Skip to Content

Custom Post Types: Build Your Own with Code

More than posts and pages

WordPress has two content types by default: posts and pages. That's enough for a blog. But if you're building a real estate site, a job portal, or a product catalog, you need your own content types. Custom Post Types make that possible.

register_post_type()

In functions.php or (better) in a dedicated plugin. The function takes a slug and an array of settings. Labels (singular, plural, menu name), supported features (thumbnail, excerpt, revisions), whether there should be an archive page, and whether it should appear in the REST API (important for Gutenberg).

We typically put the registration in a standalone plugin rather than the theme. The reason: if the client switches themes, the content type shouldn't disappear. The data doesn't vanish (it's in the database), but it becomes invisible without the registration.

Taxonomies

Complement with register_taxonomy(). A real estate site might have taxonomies "Type" (house, apartment, townhouse) and "City" (Stockholm, Gothenburg, Malmö). Hierarchical if there are subcategories, flat if not.

Template files

single-{post_type}.php for single view. archive-{post_type}.php for list view. WordPress finds them automatically based on filename. Full control over how each post type displays without touching other parts of the theme.

Practical note

We're talking about maybe 40 to 60 lines of code total. Not a big investment. But it gives you a CMS tailored to the project's needs instead of forcing everything into "posts" and "pages".

WordPress Block Patterns: Reusable Layouts
Build once, use everywhere