I would like to remove the visual editor from one specific page because if I edit this one page in Visual mode, it breaks the code. I want to make sure the client doesn’t have this option on the particular page. However, I don’t want to remove the html editor.
This line of code removes the visual editor and the html editor: remove_post_type_support(‘page’, ‘editor’);
a closer look at remove_post_type_support:
http://codex.wordpress.org/Function_Reference/remove_post_type_support
But I want to only disable the visual editor.
Initial testing, in functions.php for this theme, I have:
function remove_editor_init() {
if ( is_admin() ) {
if (is_page(2548)) {
remove_post_type_support('page', 'editor');
}
}
}
add_action('init', 'remove_editor_init');
However, the conditional statements is_admin() and is_page() don’t seem to working together.
Any suggestions?
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
In your code, calling the action admin_init makes is_admin() unnecessary. And, if not mistaken, is_page() is meant to be used in the front-end…
But the solution is the following (based on this Answer):
add_filter( 'user_can_richedit', 'wpse_58501_page_can_richedit' );
function wpse_58501_page_can_richedit( $can )
{
global $post;
if ( 28 == $post->ID )
return false;
return $can;
}
Method 2
This is how I’ve resolved this:
add_filter( 'admin_footer', 'removes_editor_visual_tab', 99 );
function removes_editor_visual_tab()
{
$post_id = $_GET['post'];
if($post_id == 1434){
?>
<style type="text/css">
a#content-tmce, a#content-tmce:hover {
display:none;
}
</style>
<script type="text/javascript">
jQuery(document).ready(function() {
document.getElementById("content-tmce").onclick = 'none';
});
</script>
<?php
}
}
You can select the page ID(s) that you’d like this to reflect on
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