PHPackages                             arraypress/wp-register-post-type - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arraypress/wp-register-post-type

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arraypress/wp-register-post-type
================================

Lightweight library for registering custom post types in WordPress with smart defaults, automatic label generation, and permalink management.

06PHP

Since Nov 30Pushed 5mo agoCompare

[ Source](https://github.com/arraypress/wp-register-post-type)[ Packagist](https://packagist.org/packages/arraypress/wp-register-post-type)[ RSS](/packages/arraypress-wp-register-post-type/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress Register Post Type
============================

[](#wordpress-register-post-type)

A powerful, elegant library for registering custom post types in WordPress with smart defaults, automatic label generation, and permalink management.

Features
--------

[](#features)

- 🎯 **Simple API** - Register post types with minimal configuration
- 🏷️ **Auto Labels** - Generates all 28 labels from singular/plural forms
- 🎨 **Icon Shortcuts** - Use simple names like 'cart' instead of 'dashicons-cart'
- 📍 **Smart Menu Positioning** - Use semantic positions like 'after:posts'
- 🔗 **Permalink Management** - Easy slug configuration with auto-flush
- 📊 **Admin Column Helpers** - Quick thumbnail column setup
- ✨ **Clean Code** - Modern PHP 7.4+, fully typed, well-documented
- 🚀 **Zero Config** - Works great with just singular/plural labels

Installation
------------

[](#installation)

Install via Composer:

```
composer require arraypress/wp-register-post-type

```

Quick Start
-----------

[](#quick-start)

### Minimal Example

[](#minimal-example)

```
use function ArrayPress\WP\RegisterPostType\register_custom_post_type;

register_custom_post_type( 'product', [
    'labels' => [
        'singular' => 'Product',
        'plural'   => 'Products'
    ]
] );

```

That's it! This creates a fully functional post type with:

- ✅ All 28 labels auto-generated
- ✅ Public and queryable
- ✅ REST API enabled
- ✅ Archive page enabled
- ✅ Title, editor, and thumbnail support

### Full Example

[](#full-example)

```
register_custom_post_type( 'product', [
    'labels' => [
        'singular' => 'Product',
        'plural'   => 'Products'
    ],
    'icon'          => 'cart',              // Simple icon name
    'supports'      => [ 'title', 'editor', 'thumbnail', 'excerpt' ],
    'has_archive'   => true,
    'show_in_rest'  => true,
    'menu_position' => 'after:posts',       // Semantic positioning
    'permalink'     => [
        'slug'       => 'shop/products',
        'with_front' => false
    ],
    'admin_columns' => [
        'thumbnail' => true                 // Add thumbnail column
    ]
] );

```

Configuration Options
---------------------

[](#configuration-options)

### Labels

[](#labels)

The library automatically generates all 28 WordPress post type labels from just two inputs:

```
'labels' => [
    'singular' => 'Product',
    'plural'   => 'Products'  // Optional - auto-pluralized if not provided
]

```

**Generated labels include:**

- name, singular\_name, add\_new, add\_new\_item, edit\_item
- new\_item, view\_item, view\_items, search\_items
- not\_found, not\_found\_in\_trash, parent\_item\_colon
- all\_items, archives, attributes, insert\_into\_item
- uploaded\_to\_this\_item, featured\_image, set\_featured\_image
- remove\_featured\_image, use\_featured\_image, menu\_name
- filter\_items\_list, items\_list\_navigation, items\_list
- item\_published, item\_published\_privately, item\_reverted\_to\_draft
- item\_scheduled, item\_updated

You can override any generated label:

```
'labels' => [
    'singular'  => 'Product',
    'plural'    => 'Products',
    'all_items' => 'All My Products'  // Override specific label
]

```

### Icon Shortcuts

[](#icon-shortcuts)

Use simple, memorable names instead of full dashicon strings:

ShortcutDashicon`cart`dashicons-cart`product`, `products`dashicons-products`store`, `shop`dashicons-store`calendar`, `event`dashicons-calendar`people`, `team`dashicons-groups`book`, `books`dashicons-book`portfolio`dashicons-portfolio`image`, `images`dashicons-format-image`video`dashicons-format-video`audio`dashicons-format-audio`download`dashicons-download`star`dashicons-star-filled`heart`dashicons-heart`location`, `map`dashicons-location`email`, `mail`dashicons-email**Examples:**

```
'icon' => 'cart'                    // Uses dashicons-cart
'icon' => 'dashicons-admin-post'    // Use full dashicon name
'icon' => 'data:image/svg+xml...'   // Use base64 SVG
'icon' => 'path/to/icon.png'        // Use custom image

```

### Menu Position

[](#menu-position)

Use semantic positioning instead of remembering numbers:

```
'menu_position' => 'after:posts'     // Right after Posts menu
'menu_position' => 'before:media'    // Right before Media menu
'menu_position' => 'after:pages'     // Right after Pages
'menu_position' => 'after:comments'  // Right after Comments
'menu_position' => 30                // Or use numeric position

```

**Available reference points:**

- `dashboard` (2)
- `posts` (5)
- `media` (10)
- `pages` (20)
- `comments` (25)
- `appearance` (60)
- `plugins` (65)
- `users` (70)
- `tools` (75)
- `settings` (80)

### Permalink Structure

[](#permalink-structure)

Configure custom URL structure:

```
'permalink' => [
    'slug'       => 'shop/products',    // Custom slug
    'with_front' => false,              // Don't prepend site's base
    'feeds'      => true,               // Enable feeds
    'pages'      => true                // Enable pagination
]

```

**Examples:**

```
// Simple slug
'permalink' => [
    'slug' => 'products'
]
// Result: yoursite.com/products/product-name/

// Nested structure
'permalink' => [
    'slug' => 'shop/products'
]
// Result: yoursite.com/shop/products/product-name/

// Disable rewrites entirely
'permalink' => [
    'disabled' => true
]

```

### Admin Columns

[](#admin-columns)

Quick shortcuts for common admin columns:

```
'admin_columns' => [
    'thumbnail' => true    // Add thumbnail column before title
]

```

### Common Options

[](#common-options)

All standard `register_post_type()` options are supported:

OptionTypeDefaultDescription`public``bool``true`Public facing post type`has_archive``bool``true`Enable archive page`show_in_rest``bool``true`Enable Gutenberg &amp; REST API`supports``array``['title', 'editor', 'thumbnail']`Features to support`hierarchical``bool``false`Allow parent/child relationships`capability_type``string``'post'`Capability type`menu_position``int|string``null`Menu position`menu_icon``string``null`Menu iconReal-World Examples
-------------------

[](#real-world-examples)

### E-Commerce Products

[](#e-commerce-products)

```
register_custom_post_type( 'product', [
    'labels' => [
        'singular' => 'Product',
        'plural'   => 'Products'
    ],
    'icon'          => 'cart',
    'supports'      => [ 'title', 'editor', 'thumbnail', 'excerpt' ],
    'has_archive'   => true,
    'show_in_rest'  => true,
    'menu_position' => 'after:posts',
    'permalink'     => [
        'slug'       => 'shop/products',
        'with_front' => false
    ],
    'admin_columns' => [
        'thumbnail' => true
    ]
] );

```

### Portfolio Items

[](#portfolio-items)

```
register_custom_post_type( 'portfolio', [
    'labels' => [
        'singular' => 'Portfolio Item',
        'plural'   => 'Portfolio'
    ],
    'icon'         => 'portfolio',
    'supports'     => [ 'title', 'editor', 'thumbnail' ],
    'has_archive'  => true,
    'menu_position' => 'after:pages'
] );

```

### Team Members

[](#team-members)

```
register_custom_post_type( 'team', [
    'labels' => [
        'singular' => 'Team Member',
        'plural'   => 'Team'
    ],
    'icon'         => 'people',
    'supports'     => [ 'title', 'editor', 'thumbnail', 'page-attributes' ],
    'hierarchical' => true,
    'has_archive'  => false,
    'public'       => true,
    'menu_position' => 'after:users',
    'admin_columns' => [
        'thumbnail' => true
    ]
] );

```

### Events with Custom Permalink

[](#events-with-custom-permalink)

```
register_custom_post_type( 'event', [
    'labels' => [
        'singular' => 'Event',
        'plural'   => 'Events'
    ],
    'icon'         => 'calendar',
    'supports'     => [ 'title', 'editor', 'thumbnail', 'excerpt' ],
    'has_archive'  => true,
    'show_in_rest' => true,
    'permalink'    => [
        'slug'       => 'events',
        'with_front' => false
    ]
] );

```

### Documentation/Knowledge Base

[](#documentationknowledge-base)

```
register_custom_post_type( 'documentation', [
    'labels' => [
        'singular' => 'Documentation',
        'plural'   => 'Docs'
    ],
    'icon'         => 'book',
    'supports'     => [ 'title', 'editor', 'comments', 'revisions' ],
    'hierarchical' => true,
    'has_archive'  => true,
    'show_in_rest' => true,
    'permalink'    => [
        'slug' => 'docs'
    ]
] );

```

### Testimonials

[](#testimonials)

```
register_custom_post_type( 'testimonial', [
    'labels' => [
        'singular' => 'Testimonial'
        // Plural auto-generated as 'Testimonials'
    ],
    'icon'         => 'star',
    'supports'     => [ 'title', 'editor', 'thumbnail' ],
    'has_archive'  => false,
    'show_in_menu' => true
] );

```

How It Works
------------

[](#how-it-works)

### Automatic Label Generation

[](#automatic-label-generation)

The library uses intelligent pluralization:

```
'Product' → 'Products'
'Category' → 'Categories'
'Person' → 'People' (you should provide this manually)

```

All 28 required labels are generated from these two inputs.

### Permalink Management

[](#permalink-management)

- Rewrites are automatically configured based on your `permalink` settings
- Rewrite rules are flushed on plugin activation (no manual flush needed)
- Supports complex structures like `shop/products/%category%`

### Icon Resolution

[](#icon-resolution)

1. Checks if it's already a full dashicon name (`dashicons-*`)
2. Checks if it's a URL or path to an image
3. Checks if it's a base64 SVG
4. Looks up shortcut in icon map
5. Assumes it's a dashicon name and adds prefix

Function Reference
------------------

[](#function-reference)

### `register_custom_post_type( string $post_type, array $config )`

[](#register_custom_post_type-string-post_type-array-config-)

Register a custom post type.

**Parameters:**

- `$post_type` (string) - Post type slug (max 20 characters, lowercase)
- `$config` (array) - Configuration array

**Returns:** `PostType` instance

**Aliases:**

- `ArrayPress\WP\RegisterPostType\register_post_type()` - Same function

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- WordPress 5.0 or higher

Best Practices
--------------

[](#best-practices)

1. **Keep slugs short** - Max 20 characters for post type slug
2. **Use singular form for slug** - `product` not `products`
3. **Provide both singular and plural** - For best label generation
4. **Test permalink structure** - Always test your URLs after registration

Troubleshooting
---------------

[](#troubleshooting)

### Permalinks not working?

[](#permalinks-not-working)

Try visiting **Settings → Permalinks** to manually flush rewrite rules.

### Post type not showing in REST API?

[](#post-type-not-showing-in-rest-api)

Make sure `show_in_rest` is `true` (it is by default).

### Custom icon not showing?

[](#custom-icon-not-showing)

Check that your icon path is correct or use one of the built-in shortcuts.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

GPL-2.0-or-later

Credits
-------

[](#credits)

Developed by [ArrayPress](https://arraypress.com/)

Support
-------

[](#support)

- [Documentation](https://github.com/arraypress/wp-register-post-type)
- [Issue Tracker](https://github.com/arraypress/wp-register-post-type/issues)

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance48

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (11 commits)")

### Embed Badge

![Health badge](/badges/arraypress-wp-register-post-type/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-wp-register-post-type/health.svg)](https://phpackages.com/packages/arraypress-wp-register-post-type)
```

###  Alternatives

[antoineaugusti/easyphpcharts

A PHP class for chartjs.org charts.

252.8k](/packages/antoineaugusti-easyphpcharts)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
