WPDevTools

Custom Post Type Generator

Stop writing repetitive PHP arrays. Configure your Custom Post Type settings below and instantly get a perfectly formatted register_post_type() code block ready for your theme or plugin.

1 General Info

Max 20 characters, lowercase alphanumeric and dashes only.

2 Supports & Features

Editor Features ('supports')

Visibility Options

functions.php / plugin.php

// Code will generate here
                        

What is a WordPress Custom Post Type (CPT)?

By default, WordPress comes with several built-in post types: Posts, Pages, Attachments, Revisions, and Navigation Menus. While these are sufficient for a basic blog, modern websites often require more structured, specialized data.

A Custom Post Type (CPT) allows you to register your own content structures. For example, if you are building a real estate website, you would create a Property CPT. If you are building a portfolio, you would create a Project CPT. This keeps your custom content logically separated from your standard blog posts, making database queries faster and content management much easier for clients.

Why use a Generator instead of a Plugin?

There are popular plugins like Custom Post Type UI (CPT UI) that allow you to create post types through the WordPress dashboard. However, professional developers generally prefer writing the code directly into a plugin or the theme's functions.php file. Here's why:

  • Performance: Relying on a heavy UI plugin to register post types adds unnecessary database queries and overhead to every page load. Hardcoded PHP arrays are processed instantly by the server.
  • Portability: When you code your CPTs, they travel perfectly with your theme or custom plugin. If you migrate a site or deploy via Git, you don't have to worry about exporting/importing plugin settings.
  • Security & Cleanliness: Fewer plugins mean a smaller attack surface and less dashboard clutter for your end-clients.

Crucial Settings Explained

When using our generator, pay attention to these specific flags in the register_post_type() arguments:

show_in_rest

This is arguably the most important boolean to check in modern WordPress. Setting this to true enables the WordPress REST API for your post type. More importantly, it activates the Gutenberg Block Editor for this post type. If you set this to false, your CPT will fall back to the old, classic TinyMCE editor.

hierarchical

Setting this to true makes your post type behave like a Page, meaning it can have "Parent" and "Child" posts. Setting it to false makes it behave like a standard Blog Post, strictly ordered by date.

has_archive

If true, WordPress will automatically create an archive route for your posts (e.g., yoursite.com/portfolio/) which displays a loop of all posts in that custom type. You can then template this using archive-portfolio.php in your theme hierarchy.

Frequently Asked Questions

Where do I paste this code?

The best practice is to create a custom site-specific plugin (e.g., in /wp-content/plugins/my-custom-cpts/) and paste the code there. This ensures your content survives if you ever change your WordPress theme. Alternatively, you can paste it at the bottom of your active theme's (or child theme's) functions.php file.

I added the code, but I get a 404 error when viewing the post!

This is the most common issue when registering a new CPT. You need to flush your rewrite rules. To do this without code, simply log in to your WP Admin, navigate to Settings > Permalinks, and hit the "Save Changes" button (you don't actually have to change anything). This rebuilds the URL routing.

How do I change the dashboard icon?

Our generator includes a field for "Menu Icon". You need to provide a valid Dashicons class string (e.g., dashicons-building). You can find the full list of available icons at the official WordPress Dashicons Resource page.