Очищаем HTML код от inline styles


Добавьте следующий код в ваш файл functions.php

Примечание: Этот фильтр работает во время сохранения / обновления поста.

add_filter( 'wp_insert_post_data' , 'filter_post_data' , '99', 2 );

function filter_post_data( $data , $postarr ) {

    $content = $data['post_content'];

    $content = preg_replace('#<p.*?>(.*?)</p>#i', '<p>\1</p>', $content);
    $content = preg_replace('#<span.*?>(.*?)</span>#i', '<span>\1</span>', $content);
    $content = preg_replace('#<ol.*?>(.*?)</ol>#i', '<ol>\1</ol>', $content);
    $content = preg_replace('#<ul.*?>(.*?)</ul>#i', '<ul>\1</ul>', $content);
    $content = preg_replace('#<li.*?>(.*?)</li>#i', '<li>\1</li>', $content);

    $data['post_content'] = $content;

    return $data;
}

Примечание: Этот фильтр работает в то время, когда функция the_content () выполняется.

add_filter( 'the_content', 'the_content_filter', 20 );

function the_content_filter( $content ) {
    $content = preg_replace('#<p.*?>(.*?)</p>#i', '<p>\1</p>', $content);
    $content = preg_replace('#<span.*?>(.*?)</span>#i', '<span>\1</span>', $content);
    $content = preg_replace('#<ol.*?>(.*?)</ol>#i', '<ol>\1</ol>', $content);
    $content = preg_replace('#<ul.*?>(.*?)</ul>#i', '<ul>\1</ul>', $content);
    $content = preg_replace('#<li.*?>(.*?)</li>#i', '<li>\1</li>', $content);
    return $content;
}

найдено тут

Автоматически очистить Microsoft Word HTML

Поместите этот код в файл functions.php вашей темы. Все, что вы вставить в TinyMCE автоматически будет проходить через встроенную в Microsoft фильтрацию слово HTML.

ПОЛЕЗНО  Уязвимости GHOST подвержены WordPress и другие PHP-приложения

/**
*	Safe Pasting for TinyMCE (automatically clean up MS Word HTML)
*/
function tinymce_paste_options($init) {
	$init['paste_auto_cleanup_on_paste'] = true;
	$init['paste_convert_headers_to_strong'] = true;
	return $init;
}
if( is_admin() ) add_filter('tiny_mce_before_init', 'tinymce_paste_options');

и еще такой фильтр:

function get_rid_of_mso_junk( $content ){
  return preg_replace( '@(mso|panose)[^:]{1,25}:[^;]+;(\s+)?(\n+)?@i', '', $content );
}

add_filter( 'content_save_pre', 'get_rid_of_mso_junk' );

и еще один фильтр:

function delete_between($beginning, $end, $string) {
    $beginningPos = strpos($string, $beginning);
    $endPos = strpos($string, $end);
    if (!$beginningPos || !$endPos) {
    return $string;
    }

    $textToDelete = substr($string, $beginningPos, ($endPos + strlen($end)) - $beginningPos);

    return str_replace($textToDelete, '', $string);
}

function clean_content( $content ){
    if( is_home() || is_single()){
        $content = delete_between('<!--[if gte mso', ';}', $content);   
        return $content;
    }else{
    return $content;
}

add_filter( 'the_content', 'clean_content' );
add_filter( 'the_excerpt', 'clean_content' );