Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to allow certain HTML elements in my comments and have edited kses.php directly in the past.

However, I have been hacked recently and replaced all the core Wordpress files and feel I would like to avoid editing those files.

Is it possible to allow more elements via the functions.php file?

share|improve this question
add comment

1 Answer

Here is an example how to allow a commenter to insert HTML5 video into the comment. Both <video> and <source> elements has two allowed attributes. preprocess_comment filter is applied when saving the comment to the DB.

See /wp-includes/kses.php for $allowedtags array structure.

function myAllowHtmlComments($comment) {
    global $allowedtags; 
    $allowedtags['video'] = array(
        'width' => true,
        'height' => true
    );
    $allowedtags['source'] = array(
        'src' => true,
        'type' => true
    );
    return $comment;
}
add_filter('preprocess_comment','myAllowHtmlComments');
share|improve this answer
    
That looks great, thank you. I have added it to my functions.php but my internet connection is not working properly so I can't test it yet. –  Phillip Dec 25 '12 at 12:20
    
Okay, I have tested it and it seems to work perfectly. Thank you very much. –  Phillip Dec 26 '12 at 7:56
    
Phillip, if so, please accept the answer. –  Max Yudin Dec 26 '12 at 9:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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