Enjoying these plugins? ☕ Buy me a coffee to support ongoing development.

Custom Post Type Generator

A user-friendly WordPress plugin that provides a GUI for registering custom post types with form fields for name, slug, supports, and menu icon. Generates and registers CPTs on the fly with exportable PHP snippets.

Single File v1.0.0 Updated 1 month ago

YT Custom Post Type Generator UI

A user-friendly WordPress plugin that provides a GUI for registering custom post types with form fields for name, slug, supports, and menu icon. Generates and registers CPTs on the fly with exportable PHP snippets.

Features

  • Visual Interface: Create custom post types without writing code
  • Complete Configuration: All register_post_type() arguments available
  • Live Registration: CPTs registered immediately via wp_options
  • Exportable Code: Generate PHP snippets for functions.php
  • Supports Management: Choose which features CPTs support
  • Menu Icon Picker: Dashicons or custom image URLs
  • Edit & Delete: Full CRUD operations for CPTs
  • Auto Slug Generation: Automatic URL-friendly slug creation
  • Validation: Form validation and error handling
  • AJAX Operations: No page reloads needed

Installation

  1. Copy yt-custom-post-type-generator-ui folder to /wp-content/plugins/
  2. Activate through WordPress 'Plugins' menu
  3. Access via 'CPT Generator' in admin menu

Usage

Creating a Post Type

  1. Go to CPT Generator in admin menu
  2. Click "+ New Post Type"
  3. Fill in required fields:
    • Plural Name: E.g., "Books", "Movies"
    • Singular Name: E.g., "Book", "Movie"
    • Slug: URL-friendly identifier (auto-generated)
  4. Select Supports features (title, editor, thumbnail, etc.)
  5. Configure Visibility & Behavior options
  6. Adjust Advanced Settings if needed
  7. Click "Save Post Type"

Editing a Post Type

  1. Click post type from sidebar list
  2. Modify any fields
  3. Click "Save Post Type"

Deleting a Post Type

  1. Click "Delete" button next to post type
  2. Confirm deletion

Exporting PHP Code

  1. Select post type from list
  2. Click "Export PHP Code"
  3. Copy generated code
  4. Paste into functions.php (if moving away from plugin)

Form Fields

Basic Information

  • Plural Name: Display name (plural)
  • Singular Name: Display name (singular)
  • Slug: URL-friendly identifier (max 20 chars)
  • Menu Icon: Dashicon class or image URL
  • Menu Position: Admin menu position (5-100)

Supports

Select which features the post type supports:

  • Title
  • Editor
  • Author
  • Featured Image
  • Excerpt
  • Comments
  • Trackbacks
  • Custom Fields
  • Revisions
  • Page Attributes
  • Post Formats

Visibility & Behavior

  • Public: Publicly visible
  • Publicly Queryable: Can be queried on frontend
  • Show UI: Show admin UI
  • Show in Menu: Appear in admin menu
  • Show in Nav Menus: Available for navigation
  • Show in REST API: Gutenberg support
  • Has Archive: Enable archive pages
  • Hierarchical: Page-like (parent/child)
  • Query Var: Enable query variable
  • Can Export: Allow export

Advanced Settings

  • Capability Type: Permission type (post/page)
  • Rewrite Slug: Custom URL slug
  • Rewrite With Front: Prepend permalink structure

Exported PHP Code

Example generated code:

<?php
/**
 * Register Custom Post Type: Books
 * Generated by YT Custom Post Type Generator UI
 */
function register_cpt_book() {
    $labels = array(
        'name'                  => __('Books', 'textdomain'),
        'singular_name'         => __('Book', 'textdomain'),
        'menu_name'             => __('Books', 'textdomain'),
        'name_admin_bar'        => __('Book', 'textdomain'),
    );

    $args = array(
        'labels'              => $labels,
        'public'              => true,
        'publicly_queryable'  => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_rest'        => true,
        'menu_position'       => 20,
        'menu_icon'           => 'dashicons-book',
        'capability_type'     => 'post',
        'hierarchical'        => false,
        'supports'            => array('title', 'editor', 'thumbnail'),
        'has_archive'         => true,
        'rewrite'             => array('slug' => 'book'),
    );

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

File Structure

yt-custom-post-type-generator-ui/
├── class-yt-custom-post-type-generator-ui.php  (~726 lines)
├── assets/
│   ├── css/
│   │   └── yt-cpt-generator-ui-admin.css  (~447 lines)
│   └── js/
│       └── yt-cpt-generator-ui-admin.js   (~276 lines)
└── README.md

Technical Details

Storage

Post types stored in wp_options table:

  • Option name: yt_cpt_generator_post_types
  • Format: Array of post type configurations

Registration

  • Hooked to init action
  • Runs on every page load
  • Flushes rewrite rules on save/delete

AJAX Endpoints

  • yt_cptg_save_post_type - Save/update post type
  • yt_cptg_delete_post_type - Delete post type
  • yt_cptg_export_code - Generate PHP code

WordPress Compatibility

  • WordPress: 5.8+
  • PHP: 7.4+
  • Tested: Up to WordPress 6.4
  • Gutenberg: Full support via show_in_rest

Security

  • Nonce verification on all AJAX requests
  • Capability checks (manage_options)
  • Input sanitization
  • Output escaping
  • SQL injection protection

Code Statistics

  • Main PHP: 726 lines
  • CSS: 447 lines
  • JavaScript: 276 lines
  • Total: ~1,449 lines
  • Meets target: ~500 line complexity

Best Practices

  • Max 20 characters for slug
  • Use lowercase slugs only
  • Enable show_in_rest for Gutenberg
  • Choose appropriate capability_type
  • Test rewrite rules after creating CPT

Troubleshooting

Post type not appearing:

  1. Check slug is valid (lowercase, no spaces)
  2. Verify "Show UI" is enabled
  3. Clear permalinks (Settings > Permalinks > Save)

Export button disabled:

  1. Save post type first
  2. Select post type from list

Changes not taking effect:

  1. Save post type
  2. Visit Settings > Permalinks
  3. Click "Save Changes"

FAQ

Q: Can I create unlimited post types? A: Yes, no limit.

Q: Will post types work if I deactivate plugin? A: No, but you can export PHP code first.

Q: Can I import post types? A: Not directly, but you can manually add to the form.

Q: Do I need to flush rewrite rules? A: Plugin does this automatically.

Q: Can I edit labels individually? A: Labels are auto-generated from names. Export code to customize.

Changelog

1.0.0 (2025-10-20)

  • Initial release
  • Visual CPT creation interface
  • Complete field support
  • PHP code export
  • AJAX operations
  • Edit/delete functionality

License

GPL v2 or later

Credits

Author: Krasen Slavov Website: https://krasenslavov.com GitHub: https://github.com/krasenslavov/yt-custom-post-type-generator-ui

Resources