Create Custom Post Type (with Gutenberg)

Use show_in_rest to enable Gutenberg block editor on custom post types.

add_action( 'init', 'create_post_type' );
function create_post_type() {
	$labels = array(
		'name' => _x('Banners', 'post type general name'),
		'singular_name' => _x('Banner', 'post type singular name'),
		'add_new' => _x('Add New Banner', ''),
		'add_new_item' => __('Add New Banner'),
		'edit_item' => __('Edit Banner'),
		'new_item' => __('New Banner'),
		'all_items' => __('All Banner'),
		'view_item' => __('View Banner'),
		'search_items' => __('Search Banner'),
		'not_found' =>  __('No Banner found'),
		'not_found_in_trash' => __('No Banner found in Trash'), 
		'parent_item_colon' => '',
		'menu_name' => __('Banners')
		$args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => false, // deactivates front end link
		'show_ui' => true, 
		'show_in_menu' => true, 
		'query_var' => true,
		'rewrite' => true,
		'capability_type' => 'post',
		'has_archive' => false, 
		'hierarchical' => false,
		'menu_position' => null,
		'show_in_rest' => true, // enables gutenberg editor
		'supports' => array( 'title', 'revisions', 'editor', 'thumbnail'),
		'exclude_from_search' => true, // hides from website search results


Place in functions.php and change “banner, Banners, Banner” to slug and name of your choice.

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.