1

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' );
  • maybe I misunderstood, do you want to just disable the html editor and leave the text editor? – Milo Jan 25 '13 at 5:50
  • I'd like to just leave the html editor on custom post types. I edited my post, shouldn't that work? – souporserious Jan 25 '13 at 6:00
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' );
0

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' );      
  • lol, looks like me and milo where writing at the same time. give the score to him as he was first – Mark Kaplun Jan 25 '13 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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