• Is there any way to enable the gutenberg editor for my CPT? The internet says it needs to have REST API set, but that’s not an option.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You have to use ‘register_post_type_args’ and ‘use_block_editor_for_post_type’ filters to enable the block editor.

    Hi again,
    this is the code I am using to enable custom CPTs in CPTonomy

    
    /*
    Enable Block Editor for custom CPTs
    */
    
    add_action('init', function(){
    
    	$cpts = array(
    		'custom-cpt-1',
    		'custom-cpt-2'
    	);
    
    	//Enable show_in_rest option
    	add_filter( 'register_post_type_args', function($args, $name) use ($cpts){
    		if(!in_array($name, $cpts)) return $args;
    		$args['show_in_rest'] = true;
    		return $args;
    	}, 10, 2);
    
    	//Enable Block Editor
    	add_filter('use_block_editor_for_post_type', function($can_edit, $post_type) use ($cpts){
    		return in_array($post_type, $cpts) ? true : $can_edit;
    	}, 10, 2);
    
    });
    
    
    • This reply was modified 6 years, 2 months ago by unapersona.
    • This reply was modified 6 years, 2 months ago by unapersona.
    • This reply was modified 6 years, 2 months ago by unapersona.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘No Gutenberg Editor or Rest API setting in CPT-onomy?’ is closed to new replies.