Created
April 3, 2017 11:02
-
-
Save madastro/ad436ecd7be56aa4d76a16052744da3d to your computer and use it in GitHub Desktop.
Cleans all given post_type of CDATA sections
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
// 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