# Register a Custom Post Type

> A ready-to-edit example that registers a "Portfolio" post type with archive, featured images and block editor support.

- Type: PHP
- Runs: Run everywhere
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: developer, custom-post-types, portfolio
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/register-custom-post-type/

## Code

```php
add_action( 'init', function () {
    register_post_type( 'portfolio', array(
        'labels'       => array(
            'name'          => 'Portfolio',
            'singular_name' => 'Portfolio Item',
            'add_new_item'  => 'Add New Portfolio Item',
            'edit_item'     => 'Edit Portfolio Item',
            'all_items'     => 'All Portfolio Items',
            'search_items'  => 'Search Portfolio',
            'not_found'     => 'No portfolio items found.',
        ),
        'public'       => true,
        'has_archive'  => true,
        'show_in_rest' => true,
        'menu_icon'    => 'dashicons-portfolio',
        'menu_position' => 20,
        'supports'     => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions' ),
        'rewrite'      => array( 'slug' => 'portfolio' ),
    ) );
} );
```

## Notes

After activating, visit Settings > Permalinks once so WordPress refreshes its URL rules.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Register a Custom Post Type" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
