Strip HTML From Comments
Removes all HTML tags from comments submitted by users who are not allowed to post unfiltered HTML, so links and formatting cannot be injected.
Opens WPIDE on
Code
add_filter( 'pre_comment_content', function ( $content ) {
if ( current_user_can( 'unfiltered_html' ) ) {
return $content;
}
return wp_strip_all_tags( $content );
}, 9 );
Notes
URLs typed as plain text are still turned into links by WordPress when displayed.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.