[wp-hackers] wp_trim_excerpt
Joost de Valk
joost at yoast.com
Tue Mar 10 21:21:09 GMT 2009
Hey,
I've been "fighting" a bit with my excerpts in my new theme, as I have
the nasty habit of sometimes adding inline script tags to my posts.
Now I found that wp_trim_excerpt does strip_tags, but it does not
remove the content within style and script tags, even though you
probably want it too. I've solved it like this for now:
function yoast_clean_excerpt($text) {
if (is_home() || is_archive()) {
$text = preg_replace('/<script type=\"text\/javascript\">([^<]+)<\/
script>/','',$text);
$text = preg_replace('/<style type=\"text\/css\">([^<]+)<\/
style>/','',$text);
}
return $text;
}
add_filter('the_content','yoast_clean_excerpt',10,1);
But I'm wondering whether wp_trim_excerpt should do that by default...
Any opinions?
Best,
Joost
More information about the wp-hackers
mailing list