Tag Archive for: tags

Multiple lines of code indented in WordPress Comments

If you want to show and mark up a single line of code in your HTML just use the code tags, however with multiple lines you need to surround the code tags with pre tags.

In WordPress comments, pre tags are not allowed by default (externally) no matter if you write them, WP will remove them. You need to add a hook to the end of your funtions.php file (Apparence/Theme Editor)


// Create function which allows more tags in comments
function allow_html_attributes_in_comment() {
  global $allowedtags;
  $allowedtags['pre'] = array('class'=>array());
}
 
// Add WordPress hook to use the function
add_action('init', 'allow_html_attributes_in_comment', 11);

This will let your users to happily post their indented code 🙂