0

I used the following code to enable image tags in the comment form. If I input the text with image upload, the image not displayed in the displayed comment.

    function my_comment_tags() {
    global $allowedtags;
    $allowedtags = array(
        'img' => array(
           'src' => array(),
           'alt' => array(),
           'title' => array(),
           'height' => array(),
           'width' => array()),
        'strong' => array(),
        'em' => array(),
        'a' => array(
          'href' => array (),
          'title' => array ())
    );
   }


   add_action('comment_post', 'my_comment_tags');

But it is not working. Is there any way to upload image in the comment form?

0

Hi please use below code in your functions.php to allow img tag in comments. For details please follow link wp_kses_allowed_html and for more details please follow trac link

add_filter( 'wp_kses_allowed_html', array( $this, 'my_kses_allowed_html_hook' ), 20, 2 );

function my_kses_allowed_html_hook( $tags, $context = null ){
    if ( 'post' == $context && ! isset( $tags['img'] ) ) {
        $tags['img'] = array(
            'src' => 1,
            'height' => 1,
            'width' => 1,
            'alt' => 1,
            'title' => 1
        );
    }

    return $tags;
}

Thanks!

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.