0

I would like to disable the visual editor for post id 416 on my local WordPress installation, to do so (following this answer) I added:

add_filter( 'user_can_richedit', 'wpse_58501_page_can_richedit' );

function wpse_58501_page_can_richedit( $can )
{
    global $post;

    if ( 416 == $post->ID )
        return false;

    return $can;
}

at the end (just before the end curly brace }) of my /wp-admin/functions.php script. Then I reloaded the tab in which I had post 416 opened to be edited (which for me http://localhost/wp/wp-admin/post.php?post=416&action=edit) and to my surprise the visual editor was still enabled for this post.

So I am here to ask how I might disable the visual editor, just for post 416. It would be nice if I could have a function that I could provide more than one post ID to, in case I create another post that needs the visual editor to be disabled.

My knowledge of PHP scripting is fairly limited, so please keep that in mind when you write your answer to this question.

  • Do you want to suppress the entire editor or will you still need access to "text" editing on that post? My question is regarding the "Visual" vs. "Text" tab that appears above the editor. – dswebsme Oct 12 '15 at 13:19
  • I want to be able to edit in text mode (I'm using the WP Editor plugin for that), for the post(s) in question, just not visual editor. – Josh Pinto Oct 12 '15 at 13:38
2

I've tested the code you provided both WITH and WITHOUT the WP Editor plugin enabled and the "Visual" tab is suppressed in both cases. This means the user is forced into "Text" mode on post 416.

To address your second request, I've modified the code to allow you to supply a list of posts that you need to suppress "Visual" editing on. Simply modify the value of "$post_array" to add as many posts as you'd like (I've included 3 in the example below).

add_filter( 'user_can_richedit', 'wpse_58501_page_can_richedit' );

function wpse_58501_page_can_richedit( $can )
{
    global $post;

    $post_array = array(1,416,247);

    if ( in_array($post->ID, $post_array) )
        return false;

    return $can;
}

If the code still isn't working for you please disable other plugins that may be running in case something else might be conflicting with this filter. Additionally, if suppressing just the "Visual" tab is not enough, please consider adding a screenshot to the question to clearly indicate what else might need to be suppressed to address your issue more accurately.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.