Skip to content

Instantly share code, notes, and snippets.

@madastro
Created April 3, 2017 11:02
Show Gist options
  • Save madastro/ad436ecd7be56aa4d76a16052744da3d to your computer and use it in GitHub Desktop.
Save madastro/ad436ecd7be56aa4d76a16052744da3d to your computer and use it in GitHub Desktop.
Cleans all given post_type of CDATA sections
// Clean CDATA in database
add_action('init', 'clean_posts');
function clean_posts() {
/* Run on the following post_types post, page, attachment and wpcf7_contact_form */
$content_posts = get_posts( array('post_type' => 'post', 'numberposts' => -1) );
$str = array('<!--[CDATA[', '<![CDATA[', '-->', ']]>', '<![CDATA[]]>');
foreach ( $content_posts as $content_post ) {
$old_content = $content_post->post_content;
$content_post->post_content = str_replace($str, '', $old_content);
wp_update_post( $content_post );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment