Custom Post Type Generator

Generate register_post_type() code with labels, supports, REST and rewrite settings.

Live output

Enable JavaScript to customise; default output below.

Prefix it with your plugin slug to avoid collisions.

Live preview book.php
<?php
/**
 * Registers the "book" post type.
 */
function my_plugin_register_book() {
	$labels = array(
		'name'          => _x( 'Books', 'Post type general name', 'my-plugin' ),
		'singular_name' => _x( 'Book', 'Post type singular name', 'my-plugin' ),
		'menu_name'     => _x( 'Books', 'Admin Menu text', 'my-plugin' ),
		'add_new_item'  => __( 'Add New Book', 'my-plugin' ),
		'edit_item'     => __( 'Edit Book', 'my-plugin' ),
		'all_items'     => __( 'All Books', 'my-plugin' ),
	);

	$args = array(
		'labels'        => $labels,
		'public'        => true,
		'has_archive'   => true,
		'show_in_rest'  => true,
		'menu_position' => 5,
		'menu_icon'     => 'dashicons-book',
		'supports'      => array( 'title', 'editor', 'thumbnail' ),
	);

	register_post_type( 'book', $args );
}
add_action( 'init', 'my_plugin_register_book' );

Output is valid and updates as you type.

Build the register_post_type() call for a custom post type without memorising every argument. Pick labels, visibility, supported features and permalinks, then copy code that follows WordPress Coding Standards.

How to use

  1. Enter a post type key (20 characters or fewer, lowercase) and a function name prefixed with your plugin slug.
  2. Set the singular and plural labels and your text domain.
  3. Choose visibility, supported features and, under More options, permalinks and taxonomies.
  4. Copy the code into your plugin’s main file or an included file.

Example

A “book” post type with an archive and block editor support:

register_post_type( 'book', array(
	'public'       => true,
	'has_archive'  => true,
	'show_in_rest' => true,
) );

Pitfalls

  • Post type keys longer than 20 characters are rejected by WordPress.
  • Register on the init hook; registering earlier breaks rewrite rules.
  • Flush permalinks once after adding the post type, or archive URLs return 404.
  • Without show_in_rest, the block editor falls back to the classic editor.

Compatibility

  • show_in_rest requires WordPress 4.7 or newer; the block editor needs 5.0 or newer.
  • The generated code runs on PHP 7.4 and newer.

Frequently asked questions

Where should I put this code?
In a plugin, not a theme, so the content stays available if the theme changes.
Why do I get a 404 on the archive page?
Rewrite rules are cached. Visit Settings, Permalinks and save once.
Can I rename the post type key later?
Existing posts keep the old key in the database, so renaming needs a data migration.

From the people who built this tool

WP Adminify

The WordPress admin, rebuilt: a dashboard worth looking at, menu and column control, a real file manager and the login page your client sees.

See WP Adminify Free version on WordPress.org

Weekly drops

New tools, when there are new tools

One email when something worth using ships. No schedule to fill, so no filler.

Your address goes nowhere else, and one click unsubscribes.