Skip to content
WORDPRESS, PHP & DATABASE

WordPress Custom Post Type Generator

Generate custom post type registration code.

  • Free
  • No signup
  • Runs in your browser

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

WordPress Custom Post Type Generator

About WordPress Custom Post Type Generator

A custom post type lets WordPress manage content that is not a normal blog post, such as courses, books, events, testimonials or products. Each type gets its own menu in the dashboard, its own archive and its own URL structure.

Type the singular name, and optionally the plural name after a comma, such as Course, Courses. The generator writes a complete registration function hooked to init, with admin labels, public visibility, an archive, a URL slug, block editor and REST API support, and the title, editor, thumbnail and excerpt features turned on.

How to use WordPress Custom Post Type Generator

  1. Type the singular name, and the plural after a comma if it is irregular, for example Course, Courses.
  2. Click Run Tool to generate the PHP.
  3. Add it to a custom plugin, activate it, then go to Settings > Permalinks and click Save Changes to refresh the URLs.

Example

Input

Course, Courses

Output

add_action( 'init', 'nhp_register_course_post_type' );
function nhp_register_course_post_type() {
    $labels = array(
        'name'          => 'Courses',
        'singular_name' => 'Course',
        'add_new_item'  => 'Add New Course',
        'edit_item'     => 'Edit Course',
        'all_items'     => 'All Courses',
        'search_items'  => 'Search Courses',
    );
    register_post_type( 'course', array(
        'labels'       => $labels,
        'public'       => true,
        'has_archive'  => true,
        'show_in_rest' => true,
        'menu_icon'    => 'dashicons-admin-post',
        'rewrite'      => array( 'slug' => 'course' ),
        'supports'     => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
    ) );
}

Common uses

  • Adding a Courses, Portfolio or Events section to a WordPress site.
  • Keeping structured content separate from blog posts for cleaner archives and sitemaps.
  • Creating a content type that can be queried with WP_Query or the REST API.

Privacy and safety

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

Frequently asked questions

Why do I get a 404 on the new post type?

WordPress needs to rebuild its rewrite rules. Visit Settings > Permalinks and click Save Changes once after adding the code.

Which name should I avoid?

Do not use reserved names such as post, page, attachment, category or action. Post type keys are limited to 20 characters, lowercase letters, numbers, dashes and underscores.

Should this go in a theme?

Put it in a plugin. If the code lives in the theme, your content type and its data become inaccessible when you switch themes.

Learn to build this yourself

Free tutorials and courses on NHP Learning cover PHP, JavaScript, SQL and WordPress, from the basics to real projects.