I read several articles about configuring the WordPress editor. For example, this snippet shows how to permanently set the editor to HTML or WYSIWYG for all contents.
I’m wondering if it’s possible to disable the WYSIWYG only when the user is creating a page, leaving it enabled for any other WordPress content type.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The best way to do this is by adding ‘user_can_richedit’ filter, like so:
add_filter( 'user_can_richedit', 'patrick_user_can_richedit');
function patrick_user_can_richedit($c) {
global $post_type;
if ('page' == $post_type)
return false;
return $c;
}
Hope it’s useful 😉
Method 2
Try this:
add_filter( 'wp_default_editor', 'rw_default_editor' );
function rw_default_editor( $type ) {
global $post_type;
if('page' == $post_type)
return 'html';
return $type;
}
Method 3
Do it like this in your functions.php file:
function remove_post_type_support_for_pages()
{
// UNCOMMENT if you want to remove some stuff
// Replace 'page' with 'post' or a custom post/content type
# remove_post_type_support( 'page', 'title' );
remove_post_type_support( 'page', 'editor' );
# remove_post_type_support( 'page', 'thumbnail' );
# remove_post_type_support( 'page', 'page-attributes' );
# remove_post_type_support( 'page', 'excerpt' );
}
add_action( 'admin_init', 'remove_post_type_support_for_pages' );
Method 4
Add the following to the post.php file inside the wp-admin directory. This code should go just before the function redirect_post() section.
// disable editor (WSYWIG) for the admin page section
if($post_type == 'page')
{
add_filter('user_can_richedit' , create_function('' , 'return false;') , 50);
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0