Archives

Disable WYSIWYG Editor For Custom Post Types

If you need to make sure that your custom post type doesn’t have the ‘visual’ tab, you can easily diable it. Suppose you have a custom post type named ‘movie’:

add_filter( 'user_can_richedit', 'disable_for_cpt' );
function disable_for_cpt( $default ) {
	global $post;
	if ( 'movie' == get_post_type( $post ) )
		return false;
	return $default;
}

Override Rich Edit Setting

It’s very easy to override the user-selected rich edit setting. Whether they’ve selected to show it or hide it, it can be reversed in a single line of code:

Always show:

add_filter( 'user_can_richedit', '__return_true' );

Always hide:

add_filter( 'user_can_richedit', '__return_false' );

Of course, if you’re going to overwrite this setting, it would make sense to also hide the user’s checkbox for this option.

add_action( 'admin_print_styles-profile.php', 'hide_rich_edit_option' );
add_action( 'admin_print_styles-user-edit.php', 'hide_rich_edit_option' );
function hide_rich_edit_option() {
    ?><style type="text/css">
    label[for=rich_editing] input { display: none; }
    label[for=rich_editing]:before { content: 'This option has been disabled (Formerly: ' }
    label[for=rich_editing]:after { content: ')'; }
    </style><?php
}

You can probably remove it more fully with Javascript, but I’ll leave that up to you.