Created
September 24, 2015 16:28
-
-
Save iagdotme/0ef9f018bd330d421a1c to your computer and use it in GitHub Desktop.
Strips out junk HTML from WP posts once imported from Blogger
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
$args = array( 'numberposts' => '150' ); | |
$recent_posts = wp_get_recent_posts( $args ); | |
foreach( $recent_posts as $recent ){ | |
$post = get_post($recent["ID"]); | |
$content = apply_filters('the_content', $post->post_content); | |
$content = strip_tags($content,"<p><br><a><img><ul><li>"); | |
$content = str_replace('style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"',"",$content); | |
$content = str_replace('style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"',"",$content); | |
$content = str_replace('border="0"',"",$content); | |
$my_post = array( | |
'ID' => $recent["ID"], | |
'post_content' => $content, | |
); | |
// Update the post into the database | |
wp_update_post( $my_post ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment