WordPress Category Editor or WYSIWYG text without a plugin

  • Update On July 31st, 2021
  • in WordPress
WordPress Category Editor or WYSIWYG text without a plugin - WordPress Category Editor or WYSIWYG text without a plugin

In WordPress, by default, the Category Description field doesn’t have the category editor or WYSIWYG text editor, so we can’t put any additional styling or images in the description. Usually, we need to add a new plugin to add that feature. But in this tutorial, I will show you how to add a Category editor or WYSIWYG text editor without a plugin in the admin. This editor allows all the options to format and design the top description area before the posts are listed. We will also remove the old description box from the table, remove the HTML filtering WordPress has turned on for this field.

Code to convert WordPress Category description to category editor or WYSIWYG text editor without a plugin

// CATEGORY TEXT EDITOR --- START
if( is_admin() ) {
// LETS REMOVE THE HTML FILTERING
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );

// LETS ADD OUR NEW CAT DESCRIPTION BOX
add_filter('edit_category_form_fields', 'filter_wordpress_category_editor');
function filter_wordpress_category_editor($tag) {
    ?>
    <table class="form-table">
        <tr class="form-field">
            <th scope="row" valign="top"><label for="description"><?php _ex('Description', 'Taxonomy Description'); ?></label></th>
            <td>
            <?php
                $settings = array('wpautop' => true, 'media_buttons' => true, 'quicktags' => true, 'textarea_rows' => '15', 'textarea_name' => 'description' );	
          wp_editor(html_entity_decode($tag->description , ENT_QUOTES, 'UTF-8'), 'description1', $settings);
            ?>
            <br />
            <span class="description"><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></span>
            </td>
        </tr>
    </table>
    <?php
}

// HIDE THE DEFAULT CAT DESCRIPTION BOX USING JQUERY
add_action('admin_head', 'remove_default_category_description');
function remove_default_category_description()
{
    global $current_screen;
    if ( $current_screen->id == 'edit-category' )
    {
    ?>
        <script type="text/javascript">
        jQuery(function($) {
            $('textarea#description').closest('tr.form-field').remove();
        });
        </script>
    <?php
    }
}
}
// CATEGORY TEXT EDITOR --- END

 

About This Author

My name is Parameshwar Roy (P. Roy), and I am a web developer. This is my personal blog to record my own thoughts. Though I am not a natural writer, I love to share my experiences. Hope my experiences will be useful to you...read more about me

Leave A Reply