我不想在“自定义帖子类型”顶部使用“所见即所得”。我想使用一个自定义字段文本区域,而不是放在自定义字段列表的底部。

这可能吗?

#1 楼

add_action('init', 'init_remove_support',100);
function init_remove_support(){
    $post_type = 'your post type';
    remove_post_type_support( $post_type, 'editor');
}


将其放置到主题函数中。php

评论


注意:我建议您在调用register_post_type()的同一回调中调用remove_post_type_support(),以确保正确的执行顺序。

–芯片Bennett
2012年11月16日下午16:21

我在functions.php中看不到register_post_type()。我正在与AdvancedCustomFields结合使用Custom Types UI。

– Scottgemmell
2012年11月16日16:42

您正在使用“自定义帖子类型” UI插件对于您的问题而言是一个非常重要的细节。 :)插件在其UI中公开了supports参数。请参阅这些屏幕截图。

–芯片Bennett
2012年11月16日16:58

#2 楼

您实际上可以禁用WYSIWYG编辑器,仅保留html源代码编辑器。在下面选择一个功能:

// disable wyswyg for custom post type, using the global $post
add_filter('user_can_richedit', function( $default ){
  global $post;
  if( $post->post_type === 'product')  return false;
  return $default;
});

// disable wyswyg for custom post type, using get_post_type() function
add_filter('user_can_richedit', function( $default ){
  if( get_post_type() === 'product')  return false;
  return $default;
});


评论


有没有办法只从摘录中删除所见即所得?我的主题已启用,我对他们的某些代码有些怀疑,我不确定是否可以删除它。我在这里提出了一个新问题:wordpress.stackexchange.com/questions/300877/…

–詹森
18年4月16日在6:13

嗨,老实说,我不知道,我的WP知识有点生锈,抱歉。我唯一可以建议的就是深入研究WP源代码,找到相关的内容,然后使用duckduckgo / google来获取文档/示例。

–biziclop
18-4-17的6:32



#3 楼

或者,您可以通过register_post_type()数组中的'supports'参数直接在$args调用中处理编辑后支持。

默认值为:'supports' => array( 'title', 'editor' )

您可以更改它可以满足您的任何需求;例如:'supports' => array( 'title' )

#4 楼

Re:此评论:


我正在将Custom Types UI与AdvancedCustomFields结合使用。


Custom Post Types UI插件公开了在其UI中使用register_post_type() $args数组参数。在这种情况下,您只需要找到Supports部分,然后禁用/取消选中Editor:



评论


即使将另一个答案设置为所选答案,这也是正确的答案。无需运行筛选器就可以删除声明CPT开始时可以排除的内容。

– Butlerblog
17年8月13日在18:56

#5 楼

我将尝试做一个更完整的答案:
如果要删除所有内容编辑器
@Oleg Butuzov答案是好的:
add_action('init', 'init_remove_support',100);
function init_remove_support(){
    $post_type = 'your post type';
    remove_post_type_support( $post_type, 'editor');
}

如果只想禁用tinymce但是让html工具栏使用
@biziclop的答案是好的:通过简单的textarea编辑tinymce编辑器
我在这里找到了答案。
add_filter('user_can_richedit', function( $default ){
  global $post;
  if( $post->post_type === 'product')  return false;
  return $default;
});


#6 楼

禁用WYSIWYG编辑器的另一种更一致的方法是仅保留html源代码编辑器-禁止对您的自定义帖子类型使用“ wp_editor_settings”过滤器。

function my_post_type_editor_settings( $settings ) {

    global $post_type;

    if ( $post_type == 'my_post_type' ) {

        $settings[ 'tinymce' ] = false;
    }

    return $settings;
}

add_filter( 'wp_editor_settings', 'my_post_type_editor_settings' );


评论


请编辑您的答案,并添加解释:为什么这可以解决问题?

– fuxia♦
17年5月11日在12:04