Make Description Field With WordPress Editor In Category Panel Instead Of Default Plain Textarea In WordPress

Among all of the features that wordpress has, taxonomy is an important one. Cause all the posts of different post types are categoried here with different taxonomies. ‘Category’ is a such one that comes in wordpress by default for the posts. You may find already that , as an admin you have the ability to create category providing its name, slug, description. But, ever you looked at the field for description ! Boring, isn’t it? How would it be , if it could be a tinmyce editor like the one that a post editor panel has. Let’s try something to do that

Get started !

You might have seen that , in category panel there list page where in the left one can create a new category using the form, here there is a description field. Another one is in the edit page of already created category. Both these two are plaing textarea. We are gonna change these two now.

Firstly a point that i wanna mention is that, there are two filters that trigger in two different pages. One in the list page of category which is called “category_add_form_fields” and another in the edit panel of category page which is called “edit_category_form_fields” . We are going to hook a function with these two filters that is going to add the wordpress tinymce editor. Thus we will get our desired editor in both pages.

add_filter('category_add_form_fields', 'cat_description');
add_filter('edit_category_form_fields', 'cat_description');
function cat_description($tag)
{
    ?>
    <div>
    	<table class="form-table">
            <tr class="form-field">
                <td>
                <div><label for="description"><?php _ex('Description', 'Taxonomy Description'); ?></label></div>
                <?php
                    $settings = array('quicktags' => true, 'textarea_name' => 'description' );
                    wp_editor(wp_kses_post($tag->description , ENT_QUOTES, 'UTF-8'), 'cat_description', $settings);
                ?>
                <br />
                <span class="description"><?php _e('You can write something here as description !'); ?></span>
                </td>
            </tr>
        </table>
    </div>
        
    <?php
}

We have done it but we also need to remove category’s default textarea , caue we don’t need that anymore. So, let’s add a function to run when admin_head action triggers.

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();
			$('#tag-description').remove();
        });
        </script>
    <?php
    }
}

‘wp_kses_post’ and ‘wp_kses_data’ are wordpress function that strip html when displaying the content , so we need to remove those. Cause, some we may want to add description as html. Add this code for that.

remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );

That’s it ! Pretty cool, right ? Hope, you will be able to add description how you want now . 🙂

Hope you will feel free to share and let others know what knew. Thank you 🙂

 

19 responses

  1. I really like what you guys are up too. This kind of clever work and reporting!
    Keep up the very good works guys I’ve added you guys to our
    blogroll.

  2. Hello, I think your blog might be having browser compatibility issues.
    When I look at your blog in Ie, it looks fine but when opening in Internet
    Explorer, it has some overlapping. I just wanted to give you a
    quick heads up! Other then that, wonderful blog!

  3. Hiya! I know this is kinda off topic nevertheless I’d figured I’d ask.
    Would you be interested in trading links or maybe guest authoring a blog post or vice-versa?
    My blog addresses a lot of the same subjects as yours and I believe we could greatly benefit from each
    other. If you might be interested feel free to send me an email.

    I look forward to hearing from you! Superb blog by the way!

  4. I blog often and I genuinely appreciate your content.
    This great article has really peaked my interest. I’m
    going to book mark your site and keep checking for new details about once per week.
    I subscribed to your RSS feed as well.

  5. My brother suggested I might like this blog. He was totally right.

    This post actually made my day. You can not imagine simply how much time I had spent for this info!
    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

three × 1 =