23

I dont want to use the WYSIWYG at the top of my Custom Post Type. I want to use a custom field textarea that i can place at bottom of my list of custom fields instead.

Is this possible?

6 Answers 6

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

place it to your themes functions.php

4
  • 3
    Note: I would recommend calling remove_post_type_support() inside the same callback that you call register_post_type(), to ensure proper order of execution. Nov 16, 2012 at 16:21
  • I dont see register_post_type() in functions.php. I am using Custom Types UI in combo with AdvancedCustomFields. Nov 16, 2012 at 16:42
  • That you're using the Custom Post Types UI Plugin is a rather important detail to your question. :) The Plugin exposes the supports parameter in its UI. Refer to these screenshots. Nov 16, 2012 at 16:58
  • 2
    This removes both editors (code & visual), not only the visual one - question was about removing WYSIWYG)
    – gordie
    Feb 4, 2022 at 15:46
22

You can actually disable the WYSIWYG editor, leaving only the html source editor. Choose a function below:

// 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;
});
2
  • is there a way to only remove the WYSIWYG from the excerpt? My theme has it turned on, and I'm dubious about some of their code, I'm not sure I can remove it. I asked this as a new question here: wordpress.stackexchange.com/questions/300877/…
    – Jason
    Apr 16, 2018 at 6:13
  • Hi, honestly, I don't know, my WP knowledge is a bit rusty, sorry. The only thing I can suggest is to dig into the WP source code, find something relevant, then duckduckgo/google it for documentation/examples.
    – biziclop
    Apr 17, 2018 at 6:32
12

Alternatively, you can handle post-editor support directly in your register_post_type() call, via the 'supports' parameter in the $args array.

The default value is: 'supports' => array( 'title', 'editor' ).

You can change it to whatever you need; for example: 'supports' => array( 'title' ).

1
  • this should be the accepted answer because this is the more rational way to do this !
    – rafa226
    Aug 19, 2021 at 8:53
6

Re: this comment:

I am using Custom Types UI in combo with AdvancedCustomFields.

The Custom Post Types UI Plugin exposes all of the register_post_type() $args array parameters in its UI.

In this case, you simply need to find the Supports section, and disable/uncheck Editor:

Custom Post Types UI Plugin - Register Post Type options

1
  • Even though another answer was set as the selected answer, this is the correct answer. There's no need to run a filter to remove something that you can just exclude when declaring the CPT to begin with.
    – butlerblog
    Aug 13, 2017 at 18:56
2

I will try to do a more complete answer :

If you want to remove all the content editor

The @Oleg Butuzov answer is good :

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

If you want only disable tinymce but let html toolbars

The @biziclop answer is good :

add_filter('user_can_richedit', function( $default ){
  global $post;
  if( $post->post_type === 'product')  return false;
  return $default;
});

In this case wp-content-editor-tools is already visible because expand-editor.js insert toolbars.

If you want to replace the tinymce editor by a simple textarea

I found the answer here.

function wpse_199918_wp_editor_settings( $settings, $editor_id ) {
    if ( $editor_id === 'content' && get_current_screen()->post_type === 'custom_post_type' ) {
        $settings['tinymce']   = false;
        $settings['quicktags'] = false;
        $settings['media_buttons'] = false;
    }

    return $settings;
}

add_filter( 'wp_editor_settings', 'wpse_199918_wp_editor_settings', 10, 2 );
0

Another, more consistent way to disable the WYSIWYG editor, leaving only the html source editor - is to disallow tinymce using "wp_editor_settings" filter for your custom post type.

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' );
1
  • Please edit your answer, and add an explanation: why could that solve the problem?
    – fuxia
    May 11, 2017 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.