Created
January 14, 2014 17:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? 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