Skip to content

Instantly share code, notes, and snippets.

@cdils
Created January 14, 2014 17:04
Show Gist options
  • Save cdils/8421802 to your computer and use it in GitHub Desktop.
Save cdils/8421802 to your computer and use it in GitHub Desktop.
Drop this in a theme's functions.php file and then resave every post/page. On saving the post/page, any inline styles will be wiped out.
<? php //remove this line
/**
* This function removes all the inline style markup from posts/pages on save.
*
* @todo Remove this code prior to site launch
*/
add_filter( 'wp_insert_post_data' , 'filter_post_data' , '99', 2 );
function filter_post_data( $data , $postarr ) {
$content = $data['post_content'];
$content = preg_replace('#<p.*?>(.*?)</p>#i', '<p>\1</p>', $content);
$content = preg_replace('#<font.*?>(.*?)</font>#i', '\1', $content);
$content = preg_replace('#<span.*?>(.*?)</span>#i', '\1', $content);
$content = preg_replace('#<ol.*?>(.*?)</ol>#i', '<ol>\1</ol>', $content);
$content = preg_replace('#<ul.*?>(.*?)</ul>#i', '<ul>\1</ul>', $content);
$content = preg_replace('#<li.*?>(.*?)</li>#i', '<li>\1</li>', $content);
$data['post_content'] = $content;
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment