• Although I can write a post in HTML without difficulty, I like using the visual editor as it allows me to think more about what I’m writing than simply how to code it. Therefore, I like having visual as the default editor.

    However, I often paste HTML into my posts (using HTML editor obviously). This disappears the next time I edit the post beacuse the visual editor loads by default.

    Is there any plugin (or piece of code) I can use to allow me to set HTML as the default editor for a specific post, rather than for every post?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You can set the html editor as the default editor (https://www.wpbeginner.com/wp-tutorials/how-to-set-html-editor-as-the-default-post-editor-in-wordpress/) but you cannot change the default editor for specific posts/pages.

    Thread Starter Dnal

    (@dnal)

    Thanks panther8, are you sure there’s no way of doing it? It seems like a fairly good idea and I can’t be the first person to have thought of it.

    Anyone?

    I have a similar problem, only the HTML bits that kept disappearing are from my Pages.

    So after seeing this, armed with the piece of code from panther8’s link, I did a bit of searching and found this page about Page Detection for Post Types in the Admin Menu and I managed to cobbled together something that works for me.

    function post_type_script($pagehook) {
        global $post_type;
        $pages = array( 'post.php', 'post-new.php' );
        if ( in_array( $pagehook, $pages ) && $post_type == 'page' ) {
            add_filter( 'wp_default_editor', create_function('', 'return "html";') );
        }
    }
    
    add_action('admin_enqueue_scripts', 'post_type_script', '', array(&$this) );

    I’m not sure how you can edit it to help with your issue, but I believe it can be used for getting the post.php to do certain things only for posts of certain criteria.

    I do know that post.php has the post ID for the post to be edited. A vague idea in my head is to store a list(array?) of the post ID of the posts which shouldn’t be edited somewhere(options?) and check with the list when loading post.php.

    Maybe somebody else can work it out. :3 I’m not confident of my code-cobbling skills for something this bit more complicated. I think it can work as a simple plugin, to be honest.

    Thread Starter Dnal

    (@dnal)

    In simple terms, what does your piece of code do?

    Drats, I meant to write that and I forgot. The link in my post actually explains the more complicated part better, but I’ll try and explain.

    Basically, it checks what page I’m loading and see if it matches the $pages array (which I put ‘post.php’ and ‘post-new.php’ because that’s where the editor is) and then it checks (with some data passed to the page) to see if the post type is ‘page’ (because I want only Pages to have HTML editor as default), and if both options are yes, it runs the add_filter to set the default editor to html editor.

    There are bits in between that I’m not sure how exactly they work, but the code is working for me.

    Thread Starter Dnal

    (@dnal)

    Ah, very clever. Thanks!

    I’ll give it a go.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Set HTML editor as default for specific pages only?’ is closed to new replies.