Ở bài viết này, mình sẽ hướng dẫn các bạn Cách tránh WYSIWYG Editor tự xoá thẻ HTML và chống sinh ra các thẻ HTML mới không mong muốn
Thêm đoạn code sau vào function.php
function allow_custom_html($tags)
{
$tags['iframe'] = [
'src' => true,
'height' => true,
'width' => true,
'frameborder' => true,
'allowfullscreen' => true,
];$tags['script'] = [
'type' => true,
'src' => true,
];
return $tags;
}
add_filter('wp_kses_allowed_html', 'allow_custom_html', 10, 1);function allow_all_tinymce_html($settings)
{
$settings['valid_elements'] = '*[*]'; // Allows all HTML tags and attributes
return $settings;
}
add_filter('tiny_mce_before_init', 'allow_all_tinymce_html');remove_filter('the_content', 'wpautop');
remove_filter('the_excerpt', 'wpautop');
Chúc các bạn thành công