Remove WYSIWYG editor on all custom post type EXCEPT regular posts

Trying to remove the WYSIWYG Editor on all post types except the default pages and posts.

Shouldn’t this work

// Remove WYSIWYG Editor
function remove_wysiwyg( $hook ) {
    if ( $hook != 'post-new.php' || $hook != 'post.php' )
    add_filter('user_can_richedit', '__return_false');
}
add_action( 'init', 'remove_wysiwyg' );

Related posts

Leave a Reply

2 comments

  1. A bit involved, but this should work:

    function remove_wysiwyg() {
        global $pagenow;
        if ( 'post.php' == $pagenow ) {
            $type = get_post_type( $_GET['post'] );
            if( 'post' != $type || 'page' != $type )
                add_filter('user_can_richedit', '__return_false');
        } elseif ( 'post-new.php' == $pagenow ) {
            if( isset( $_GET['post_type'] ) && 'page' != $_GET['post_type'] )
                add_filter('user_can_richedit', '__return_false');
        }   
    }
    add_action( 'admin_init', 'remove_wysiwyg' );
    
  2. You should look for the post type in the URL or the type of the post itself, and you can be more specific and run the code for only admin sessions

    // Remove WYSIWYG Editor
    function remove_wysiwyg( $hook ) {
        global $post;
        global $pagenow;
    
        if ( $pagenow== 'post-new.php' && isset($_GET['post_type'])) || // if a new post page check the post type from the URL
           (($pagenow== 'post.php' ) && // If editing  existing post check the post type of the post
              (($post->post_type != 'post') && ($post->post_type != 'page')))
          add_filter('user_can_richedit', '__return_false');
    }
    
    add_action( 'admin_init', 'remove_wysiwyg' );