問題描述

我創建了一個自定義的帖子類型,我想在發佈/編輯頁面中隱藏主要的 textarea 內容。

可能嗎 ?

謝謝!

最佳解決方案

是的,從您的自定義帖子類型中刪除編輯器支持。

你可以通過兩種方法來實現。

  1. 註冊您的自定義帖子類型時:

例:

$args = array(
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'capability_type' => 'post',
    'has_archive' => true,
    'supports' => array('title','author','thumbnail','excerpt','comments')
);
register_post_type('book',$args);

2. 如果您的代碼未定義自定義帖子類型 (即某些其他插件/主題已定義自定義帖子類型),請使用 remove_post_type 支持。

例:

add_action('init', 'my_rem_editor_from_post_type');
function my_rem_editor_from_post_type() {
    remove_post_type_support( <POST TYPE>, 'editor' );
}

次佳解決方案

註冊您的自定義帖子類型時,不要指定對編輯器的支持。

 $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'has_archive' => true,
    'hierarchical' => false,
    'menu_position' => null,
    // on the supports param here you see no 'editor'
    'supports' => array('title','author','thumbnail','excerpt','comments')
  );
  register_post_type('book',$args);

更多信息請參閲:Function Reference/register post type

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。