I’ve been trying to set up the comments section of a site I am working on to use the default WordPress WYSIWYG (TinyMCE). But it’s harder than expected.

I used this tutorial to take me almost all the way there. The tutorial makes it so I can use the WYSIWYG as the comment form, and it even has a fix when you click on a comment reply link (so that it will work there too).

The problem occurs when you click on a comment reply link, then cancel. This causes the original WYSIWYG (the one that first loads at the bottom of the comment stream) to break.

I have no idea how to make this WYSIWYG work again. Any thoughts or ideas?

Any help is greatly appreciated!

2 s
2

Give this a shot:

<?php
/* Add WYSISYG editor to comment form. */
add_filter( 'comment_form_field_comment', 'wpse_64243_comment_editor' );

function wpse_64243_comment_editor( $field ) {

    if (!is_single()) return $field; //only on single post pages.
    global $post;

    ob_start();

    wp_editor( '', 'comment', array(
        'textarea_rows' => 15
    ) );

    $editor = ob_get_contents();

    ob_end_clean();

    //make sure comment media is attached to parent post

    $editor = str_replace( 'post_id=0', 'post_id='.get_the_ID(), $editor );

    return $editor;

}

Leave a Reply

Your email address will not be published. Required fields are marked *