删除所有自定义帖子类型(常规帖子除外)上的所见即所得编辑器

时间:2013-01-25 作者:souporserious

正在尝试删除除默认页面和帖子之外的所有帖子类型上的所见即所得编辑器。

这不应该吗

// 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 个回复
SO网友:Milo

有点复杂,但这应该可以:

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

SO网友:Mark Kaplun

您应该在URL中查找帖子类型或帖子本身的类型,您可以更具体一些,只为管理员会话运行代码

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

结束

相关推荐

wysiwyg is scrambled

我对wordpress编辑器有问题。它不断删除我的输入并扰乱内容。我如何解决这个问题?