Skip to content

Instantly share code, notes, and snippets.

@iagdotme iagdotme/strip.php
Created Sep 24, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.