WordPress Core Schema Builder

WordPress CPT Generator & Taxonomy Builder

Generate clean, production-ready PHP boilerplate for custom post types and taxonomies with full UI arguments, Dashicons, and Gutenberg REST API support.

Custom Meta Box Fields Builder
Fields are automatically escaped and saved via secure nonce verification and capability checks in save_post.
cpt-registration.php • Ready for functions.php or plugin Hooked to init & add_meta_boxes
How to Use This Tool

How to Use the WordPress CPT Generator

Follow this 4-step workflow to configure, generate, and deploy production-ready code into your WordPress theme.

1

Set Labels, Slug & Dashicon Identifier

Choose a preset (Portfolio, Testimonials, Team) or enter Singular Label, Plural Label, Post Type Key (keep lowercase alphanumeric/underscores <= 20 chars), and Dashicon.

Input: Labels, <= 20-Char Key, Dashicon
2

Select Supported Editor Features & Toggles

Check post-type supports (Title, Content Editor, Featured Image, Excerpt, Custom Fields, Revisions) and toggle Gutenberg REST API, Hierarchical behavior, or Taxonomy.

Compatibility: Gutenberg & /wp/v2/{slug}
3

Add Custom Meta Box Fields (Optional)

With Custom Meta Box Builder enabled, click "+ Add Custom Field" to define Field Label, Meta Key ID, and type (text, url, number, textarea) with nonce saving.

Security: wp_nonce_field & Sanitization
4

Download cpt-{slug}.php & Flush Permalinks

Copy the PHP or click "Download .php" (cpt-{slug}.php), include it in a site plugin or inc/cpt.php, and visit Settings > Permalinks > Save Changes to avoid 404s.

Action Required: Flush WP Rewrite Rules

Structuring custom domain models—such as Portfolios, Case Studies, Testimonials, Team Directories, or Events—without heavy database plugins keeps WordPress sites fast and maintainable. The CodeToWP WordPress CPT Generator gives WordPress developers, agencies, and freelancers instant, dependency-free PHP boilerplate combining register_post_type(), optional taxonomies, and nonce-protected meta boxes.

WordPress CPT Generator interface for register_post_type and custom taxonomies
Generate native PHP post types, hierarchical category taxonomies, and sanitized admin meta boxes.

Who the WordPress CPT Generator Is Built For

Visual CPT UI plugins store post type configurations in WordPress options tables, couple schema management to admin dashboards, and make Git-based code reviews harder. Writing full register_post_type() label arrays, taxonomy registrations, and nonce-checked save_post handlers manually is repetitive and error-prone.

This WordPress CPT Generator compiles readable, handbook-compliant PHP code in seconds—ready for your theme’s inc/cpt.php or a site-specific companion plugin without plugin lock-in.

Features, Settings & Supported Outputs

  • Sample Presets & Identity Fields: Load Portfolio Projects, Client Testimonials, or Team Members presets, or configure Singular Label, Plural Label, Post Type Key slug, and Menu Icon Dashicon class (defaults to dashicons-portfolio).
  • Supported Feature Checkboxes & Behavior Toggles: Toggle post-type features (title, editor, thumbnail, excerpt, custom-fields, revisions) plus switches for Gutenberg/REST API support (show_in_rest), Hierarchical (Page-like parent/child hierarchy), companion hierarchical Taxonomy registration, and the Custom Meta Box Builder.
  • Interactive Custom Meta Box Builder: Click + Add Custom Field to append fields supporting four input types (text, url, number, and textarea), complete with WordPress nonces (wp_nonce_field()), autosave protection, current_user_can() checks, and type-matched sanitization (sanitize_text_field, esc_url_raw, intval, sanitize_textarea_field).
  • Direct Export: Copy the compiled PHP or download cpt-{slug}.php.

Practical Example: Portfolio CPT with Taxonomy & Client Field

Sample Tool Settings

Singular:    Portfolio         | Plural: Portfolio Items
Slug:        portfolio         | Dashicon: dashicons-portfolio
Toggles:     show_in_rest (ON), Include Taxonomy (ON), Custom Meta Box (ON)
Custom Field: Label = "Client Name", ID = "client_name", Type = "text"

Expected Generated PHP Output Excerpt

function codetowp_register_cpt_portfolio() {
	register_post_type( 'portfolio', array(
		'public'       => true,
		'has_archive'  => true,
		'show_in_rest' => true,
		'menu_icon'    => 'dashicons-portfolio',
		'supports'     => array( 'title', 'editor', 'thumbnail', 'revisions' ),
	) );
	register_taxonomy( 'portfolio_category', array( 'portfolio' ), array(
		'hierarchical'      => true,
		'show_in_rest'      => true,
		'show_admin_column' => true,
	) );
}
add_action( 'init', 'codetowp_register_cpt_portfolio' );

Result Explanation: The output registers portfolio and portfolio_category on init following the official WordPress register_post_type() reference, plus nonce-checked _client_name saving on save_post_portfolio.

Practical Use Cases

  • WordPress Developers: Version-control clean CPT schemas inside custom plugins or starter themes with zero plugin overhead.
  • Frontend Developers: Set up custom post endpoints (/wp-json/wp/v2/{slug}) quickly for Gutenberg or headless data modeling.
  • Agencies: Standardize repeatable Portfolio, Testimonial, Case Study, and Team modules across client retainers.
  • Freelancers: Add structured metadata inputs (client URLs, ratings, bios) in classic admin meta boxes without purchasing custom-field suites.

Limitations & Compatibility

  • Manual 20-Character Key & Quote Discipline: While WordPress core enforces a 20-character maximum on post type keys (lowercase alphanumeric and underscores only), the Slug input field does not automatically block longer keys or special characters—verify your slug stays 20 characters or fewer and avoid apostrophes/quotes inside labels or field names.
  • Fixed Architectural Defaults: Output defaults to prefix codetowp_, text domain 'codetowp', public => true, has_archive => true, menu_position => 20, and a hierarchical taxonomy (`{singular} Category`). Adjust these keys directly in PHP if you need private post types or non-hierarchical tags.
  • Meta Box REST Exposure & Persistence: Generated meta boxes work cleanly in the WordPress admin editor (including block editor screens) and save sanitized _{id} post meta, but do not automatically emit register_post_meta(..., ['show_in_rest' => true]); note also that the Supports checkboxes revert to defaults after a full browser reload, whereas labels and custom meta rows persist in localStorage.
  • Compatibility: Compatible with WordPress 6.0–6.7+ and PHP 8.0–8.3+.

Next Steps & Related CodeToWP Tools

Flush rewrite rules under Settings > Permalinks > Save Changes after activating your WordPress CPT Generator code file, pair your custom schema with a starter theme from our Starter Theme ZIP Generator or custom cards via the HTML to Elementor Widget Builder, and read Building Custom Post Types and Taxonomies in WordPress.

Frequently Asked Questions

WordPress caches permalink rewrite rules in the database. After saving cpt-{slug}.php into your plugin or theme, open WP Admin > Settings > Permalinks and click "Save Changes" once to flush rewrite rules.

For client production sites, putting CPT and taxonomy code inside a site-specific companion plugin (such as codetowp-core) ensures portfolio items, testimonials, and custom metadata remain intact even if the theme changes.

WordPress strictly enforces a 20-character maximum on post type keys and expects lowercase letters, numbers, and underscores only (no spaces or uppercase letters). Always verify your slug fits within 20 characters before deploying.

The Custom Meta Box Builder supports text, url, number, and textarea fields. Each save_post_{slug} handler verifies wp_nonce_field(), skips DOING_AUTOSAVE, checks current_user_can( 'edit_post' ), and sanitizes via sanitize_text_field(), esc_url_raw(), intval(), or sanitize_textarea_field().

Enabling "Show in REST" exposes the post type itself and taxonomies at /wp-json/wp/v2/{slug}, while custom meta boxes render in the editor sidebar/panel. Add register_post_meta(..., array( 'show_in_rest' => true )) in PHP if headless consumers need meta fields via REST.