Trong lúc hoàn thành plugin WP Extra, Ad có ghi ra 1 số hàm nhằm giúp các bạn tự xây dựng cho mình 1 hệ thống các tính năng hay cho website của riêng bạn.
Lưu ý: Nhớ backup trước khi thực hiện thêm bớt hàm functions
1. Xoá định dạng các thẻ html không cần thiết
Giải thích: Mã này chỉ hoạt động trong Bài Viết (Post), không hoạt động đối với Trang (Page) nhằm tránh xung đột với các thẻ HTML trong thiết kế theme.
add_filter('tiny_mce_before_init','vnex_clean_html_tinymce');
function vnex_clean_html_tinymce ($in) {
global $post_type;
if ( $post_type === 'post' ) {
$in['paste_preprocess'] = "function(plugin, args){
var whitelist = 'p,b,strong,i,em,h2,h3,h4,h5,h6,ul,li,ol,a,href';
var stripped = jQuery('<div>' + args.content + '</div>');
var els = stripped.find('*').not(whitelist);
for (var i = els.length - 1; i >= 0; i--) {
var e = els[i];
jQuery(e).replaceWith(e.innerHTML);
}
stripped.find('*').removeAttr('id').removeAttr('class').removeAttr('style');
args.content = stripped.html();
}";
}
$in['forced_root_block'] = "";
$in['force_p_newlines'] = true;
return $in;
}