[wp-hackers] wp_trim_excerpt

Jason Webster jason at intraffic.net
Wed Mar 11 02:20:53 GMT 2009


Joost,

You should watch your regex for removing the script tags there...
"<" is still a valid character in javascript. So, your regex won't strip out script tags that are 
escaped with CDATA tags, or use the less than operator, or contain a string with the less than 
character.

A better bet may be to use (.+?), which will take out everything until it hits the (first) closing 
script tag.

On 10/03/2009 2:21 PM, Joost de Valk wrote:
> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list