Visual Editor for Category and Tag Descriptions
Replaces the plain description box on the category and tag edit screens with the visual editor, and keeps headings, lists, images and links that WordPress would otherwise strip.
Opens WPIDE on
Code
// Taxonomies whose edit screen gets the visual editor for the description.
$wpide_rich_description_taxonomies = array( 'category', 'post_tag' );
// Keep headings, images, lists and links in descriptions (WordPress normally allows only a few inline tags).
add_action( 'init', function () {
if ( current_user_can( 'manage_categories' ) ) {
remove_filter( 'pre_term_description', 'wp_filter_kses' );
add_filter( 'pre_term_description', 'wp_filter_post_kses' );
}
} );
foreach ( $wpide_rich_description_taxonomies as $wpide_rich_tax ) {
add_action( $wpide_rich_tax . '_edit_form_fields', function ( $term ) {
echo '<tr class="form-field wpide-rich-description"><th scope="row"><label for="wpide_term_description">Description</label></th><td>';
wp_editor( $term->description, 'wpide_term_description', array(
'textarea_name' => 'description',
'textarea_rows' => 10,
'media_buttons' => current_user_can( 'upload_files' ),
) );
echo '<p class="description">Shown on the archive page if your theme displays descriptions.</p></td></tr>';
} );
}
// Hide the plain description box that the editor replaces.
add_action( 'admin_head-term.php', function () use ( $wpide_rich_description_taxonomies ) {
if ( in_array( get_current_screen()->taxonomy, $wpide_rich_description_taxonomies, true ) ) {
echo '<style>.term-description-wrap{display:none}</style>';
}
} );
add_action( 'admin_footer-term.php', function () use ( $wpide_rich_description_taxonomies ) {
if ( in_array( get_current_screen()->taxonomy, $wpide_rich_description_taxonomies, true ) ) {
// Remove the original field so only the editor's value is submitted.
echo '<script>(function(){var row=document.querySelector(".term-description-wrap");if(row){row.parentNode.removeChild(row);}})();</script>';
}
} );
Notes
Your theme must display term descriptions; add other taxonomies to the list at the top.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.