サポート » 使い方全般 » 投稿タイプでエディタを切り分ける方法について

  • 解決済 non888

    (@non888)


    投稿によって、クラシックエディタとブロックエディタの切り分けを行いたいと思っております。

    ■ブロックエディタを使用したい投稿タイプ名
    ・post
    ・report

    調べたところ下記コードを「functions.php」に追加すると切り分けができることを知り、試してみたところ、post_typeのif文を1つだけの指定であればうまく切り分けができるのですが、複数指定した場合すべてクラシックエディタで表示されてしまいます。

    ■切り分けができたコード

    add_filter('use_block_editor_for_post_type', 'disable_block_editor', 10, 2);
    function disable_block_editor($use_block_editor, $post_type)
    {
      if ($post_type !== 'post') return false;
      return $use_block_editor;
    }

    ■切り分けができないコード

    add_filter('use_block_editor_for_post_type', 'disable_block_editor', 10, 2);
    function disable_block_editor($use_block_editor, $post_type)
    {
      if ($post_type !== 'post' || $post_type !== 'report') return false;
      return $use_block_editor;
    }
    add_filter('use_block_editor_for_post_type', 'disable_block_editor', 10, 2);
    function disable_block_editor($use_block_editor, $post_type)
    {
      if ($post_type !== 'post' || $post_type !== 'report'){
       return false;
      }
      return $use_block_editor;
    }
    add_filter('use_block_editor_for_post_type', 'disable_block_editor', 10, 2);
    function disable_block_editor($use_block_editor, $post_type)
    {
      if ($post_type !== 'post'){
       return false;
      } elseif($post_type !== 'report'){
       return false;
      }
      return $use_block_editor;
    }

    複数指定したい場合はどのように設定したほうが良いのでしょうか。
    よろしくお願いいたします。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • こんにちは

    偽 (False)であるもの (post, report 以外) が含まれることを示す (否定論理積) なので AND では?
    if ($post_type !== 'post' || $post_type !== 'report') return false;

    if ($post_type !== 'post' && $post_type !== 'report') return false;

    または、
    if ( ! in_array( $post_type, array( 'post', 'report') ) ) return false;

    トピック投稿者 non888

    (@non888)

    @ishitaka

    ありがとうございます。
    お教えいただいた方法でうまく動作いたしました。

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「投稿タイプでエディタを切り分ける方法について」には新たに返信することはできません。