WPブロックエディタが有効にできない
数年前に、何度かチェックしたもののあまり実用性を感じられず、ずっと見ぬふりしていたWordpressの新機能ブロックエディタ(旧Gutenberg)。いざ使おうとしたら有効にならず!!(投稿画面が真っ白になってしまう)。ブラウザキャッシュの削除など、数日いろいろ試した結果、いくつかの方法で解決したのでメモ。
特定のカスタム投稿タイプのみ使用
私の場合、ある投稿タイプのみ使用したかったのでfunctions.phpに以下分岐を記載
add_filter( 'use_block_editor_for_post', function( $use_block_editor, $post ) {
if ( 'post_type_name' === $post->post_type ) {
$use_block_editor = true;
}else{
$use_block_editor = false;
}
return $use_block_editor;
}, 10, 2 );
Classic Editor
Classic Editorプラグインを有効にすると、管理画面 > 設定 > 投稿設定に以下の項目が出てくると思うので、「Default editor for all users」を「Block editor」に。
※「Allow users to switch editors」をYesにすると各投稿において選択できるようになるみたいです。
register_post_type
これもfunctions.php。投稿タイプを作成するregister_post_typeに「show_in_rest=>true」を記載する必要があるらしい
register_post_type( 'post_type_name',
array(
'labels' => array(
'name' => __( '投稿タイプ名' ),
'singular_name' => __( '投稿タイプ名' )
),
'public' => true,
'show_ui' => true,
'show_in_rest' => true,//★これ
//..以下略
)
);
解決!
これでだめなら、ブラウザキャッシュの削除やACFなどカスタムフィールド系プラグインでエディタを非表示などに設定してないかを、要確認!

