Skip to content

Instantly share code, notes, and snippets.

@iagdotme
Created September 24, 2015 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iagdotme/0ef9f018bd330d421a1c to your computer and use it in GitHub Desktop.
Save iagdotme/0ef9f018bd330d421a1c to your computer and use it in GitHub Desktop.
Strips out junk HTML from WP posts once imported from Blogger
$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