# Enable the Block Editor and REST API for a Plugin's Post Type

> Turns on REST API support for post types registered without it, which also switches them to the block editor and makes them available to apps and headless sites.

- Type: PHP
- Runs: Run everywhere
- Category: [Custom Post Types & Fields](https://wpide.com/library/category/post-types/)
- Tags: rest-api, gutenberg, custom-post-types
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/enable-rest-for-post-type/

## Code

```php
// Post type => REST base (the URL part after /wp-json/wp/v2/).
$wpide_rest_types = array(
    'portfolio' => 'portfolio',
);

add_filter( 'register_post_type_args', function ( $args, $post_type ) use ( $wpide_rest_types ) {
    if ( isset( $wpide_rest_types[ $post_type ] ) ) {
        $args['show_in_rest'] = true;
        $args['rest_base']    = $wpide_rest_types[ $post_type ];
    }

    return $args;
}, 10, 2 );
```

## Notes

The post type also needs editor support for the block editor to appear. Test the plugin's own meta boxes, which may not all work in the block editor.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Enable the Block Editor and REST API for a Plugin's 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/
