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

2 Answers 2

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

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.