Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Created February 12, 2013 04:29
Show Gist options
  • Save lgedeon/4760250 to your computer and use it in GitHub Desktop.
Save lgedeon/4760250 to your computer and use it in GitHub Desktop.
strips control characters from feed content
// non-prefixed version submited to core as patch
function tc_strip_for_xml( $string ) {
// Store the site charset as a static to avoid multiple calls to get_option()
static $is_utf8;
if ( ! isset( $is_utf8 ) ) {
$is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
}
if ( ! $is_utf8 ) {
return $string;
}
return preg_replace( '/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string );
}
function tc_the_content_strip_for_xml( $content ) {
if ( is_feed() )
$content = tc_strip_for_xml( $content );
return $content;
}
add_filter( 'the_content', 'tc_the_content_strip_for_xml' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment