also would like to know how to do this
I had a look into this. In normal circumstances I think wordpress does it automatically. You should be able to find this code in the formatting.php file or another file (can’t remember which).
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text, $allowed_tags);
However, a plugin may interfere, such as a plugin for advanced excerpts or any plugin involved in creating an excerpt.
Therefore make sure that code is in there. So you may want to study the plugin’s code and add that code to it. I added the following and it got rid of most unwanted code in excerpts:
$text = str_replace(']]>', ']]>', $text);
$text = preg_replace('@.*?</script>@si', '', $text); //remove javascript
$text = preg_replace('@<![\s\S]*?--[ \t\n\r]*>@', '', $text); // remove CDATA
$text = strip_tags($text, $allowed_tags);
$text = preg_replace('<code>\[[^\]]*\]</code>','',$text); //remove anything in square brackets