[wp-hackers] wp_trim_excerpt

Casey Bisson casey.bisson at gmail.com
Wed Mar 11 13:50:05 GMT 2009


Depending on how much you want to remove, the wp_filter_nohtml_kses()  
function might do the trick. It strips scripts, styles, simple html,  
and nasty stuff, returning just plain old text.

--Casey

http://maisonbisson.com


On Mar 10, 2009, at 5: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