WordPress: Solution to backend editor filtering some Html tags by default

888u

Last update at :2024-07-06,Edit by888u

Based on security considerations, the WordPress backend editor will filter out some HTML tags by default when publishing articles, such as script, onclick, etc. But many times, we may use these HTML tags to meet special needs when publishing articles. Currently, articles on the Internet basically need to modify the WordPress core file, which will become invalid when the WordPress version is upgraded, and it is also more dangerous. This article will introduce how to prevent the WordPress backend editor from filtering some HTML tags by default through theme files.

In the WordPress theme functions.php file, add the following code:

kses_remove_filters()

The implementation code of this function is as follows:

function kses_remove_filters() {
//Normal filtering.
remove_filter( 'title_save_pre', 'wp_filter_kses' );

// Comment filtering.
remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
remove_filter( 'pre_comment_content', 'wp_filter_kses' );

// Global Styles filtering.
remove_filter( 'content_save_pre', 'wp_filter_global_styles_post', 9 );
remove_filter( 'content_filtered_save_pre', 'wp_filter_global_styles_post', 9 );

// Post filtering.
remove_filter( 'content_save_pre', 'wp_filter_post_kses' );
remove_filter( 'excerpt_save_pre', 'wp_filter_post_kses' );
remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' );
}

If our theme does not need to cancel all filtering methods, we can also select the filtering methods to be canceled based on the above code. For example, we call the following code separately in functions.php:

remove_filter( 'content_save_pre', 'wp_filter_post_kses' );

Recommended site search: 6 yuan Alibaba Cloud shared virtual host, check IP address, mainland China registration-free server, dynamic IP dial-up server, Foshan high-defense server, how to register the website, asp.net space, Zhenjiang high-defense server, asp Host, Korean server recommendation,

WordPress: Solution to backend editor filtering some Html tags by default

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码