Safely Allow Code Blocks in WordPress Comments
WordPress sanitizes HTML in comments by default for security. The <pre> tag is stripped unless you explicitly whitelist it. Here’s how to enable it without compromising security. Using wp_allowed_post_html Filter The proper approach is to whitelist <pre> and related tags via the wp_allowed_post_html filter: function allow_pre_in_comments( $allowed ) { $allowed[‘pre’] = array(); $allowed[‘code’] = array(…
