How to enable HTML editing in category descriptions?
Sometimes either by WordPress versions, themes, among others, the edition of the description of the categories does not accept html, but we can extend or recover this function with a simple code.
In order to edit the category descriptions in HTML we must implement the following snippet:
/**
* Allow HTML in (category, tag) descriptions
*/
foreach ( array( 'pre_term_description' ) as $filter ) {
remove_filter( $filter, 'wp_filter_kses' );
if ( ! current_user_can( 'unfiltered_html' ) ) {
add_filter( $filter, 'wp_filter_post_kses' );
}
}
foreach ( array( 'term_description' ) as $filter ) {
remove_filter( $filter, 'wp_kses_data' );
}
You can embed it in your WP with Code Snippets or by your custom plugin. Once activated, HTML editing will be enabled.
But we can do more:
//Allow shortcodes in descriptions
add_filter( 'term_description', 'do_shortcode' );
Now we will also be able to insert Shortcodes such as those generated by Elementor Pro and AnyWhere Elementor. The two codes activate these resources in both categories and tags.
The complete sequence would look like this:
/**
* Allow HTML in (category, tag) descriptions
*/
foreach ( array( 'pre_term_description' ) as $filter ) {
remove_filter( $filter, 'wp_filter_kses' );
if ( ! current_user_can( 'unfiltered_html' ) ) {
add_filter( $filter, 'wp_filter_post_kses' );
}
}
foreach ( array( 'term_description' ) as $filter ) {
remove_filter( $filter, 'wp_kses_data' );
}
//Allow shortcodes in descriptions
add_filter( 'term_description', 'do_shortcode' );
I hope it helps and see you next time.