Is it possible to remove WYSIWYG for a certain Custom Post Type?

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?

Topic wysiwyg custom-post-types Wordpress

Category Web


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 );

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;
});

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' );

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


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' ).


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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.