This latest plugin did cause a bit of trouble when I tried to put it together originally but after a bit of thinking outside the box it’s finally up and running. You do need to have WordPress 3.3 installed for this tinymce editor for category description plugin to work.
As you are probably aware the latest version of WordPress 3.3 brought in the wp_editor api. This means that the old fashioned way of calling the tinymce editor to forms in WordPress no longer works.
Tinymce for category description in WordPress 3.3.
It’s not straightforward to assign the editor to an established form or field. This is true of the category description textarea in WordPress. I spent a lot of time trying to attach the tinymce to the field with varying degrees of success – and mainly failure. Eventually I gave up trying to assign the editor to the established category description field and started from scratch.
This plugin adds a new form field to the WordPress category editor – but it feeds its information into the same database field as the default box. By using a filter to add in the new textarea I could be sure that the wp_editor api was being called correctly.
Then I added another jquery based filter to hide the original category description box. Once the orignal box was hidden it just looks as though the default category field has an editor attached – depite the fact it is a completely new textarea.
html in category description of WordPress 3.3.
One of the problems that you can have when you use html in the category description field is that when you are on the category adminsitration page the table can be messed up as the decription column contains a lot more information and formating. Add a few images and the look of the admin page can get totally out of hand.
The CategoryTinymce plugin deals with this by running an extra filter through the page to remove the category description column. This brings the table back to a nice looking feature – though of course you will not see the description until you go into the main edit category page.
You can download the plugin from the link below. If you prefer to use the code directly rather than have a plugin add the tinymce then add the following code into your functions file:
// 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
define('description1', 'Category_Description_option');
add_filter('edit_category_form_fields', 'description1');
function description1($tag) {
$tag_extra_fields = get_option(description1);
?>
<table>
<tr>
<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 ), 'description1', $settings); ?>
<br />
<span><?php _e('The description is not prominent by default, however some themes may show it.'); ?></span>
</td>
</tr>
</table>
<?php
}
// quick jquery to hide the default cat description box
function hide_category_description() {
global $current_screen;
if ( $current_screen->id == 'edit-category' ) {
?>
<script type="text/javascript">
jQuery(function($) {
$('select#parent').closest('tr.form-field').hide(); $('textarea#description, textarea#tag-description').closest('tr.form-field').hide();
});
</script> <?php
}
}
// lets hide the cat description from the category admin page
add_action('admin_head', 'hide_category_description');
function manage_my_category_columns($columns)
{
// only edit the columns on the current taxonomy
if ( !isset($_GET['taxonomy']) || $_GET['taxonomy'] != 'category' )
return $columns;
// unset the description columns
if ( $posts = $columns['description'] ){ unset($columns['description']); }
return $columns;
}
add_filter('manage_edit-category_columns','manage_my_category_columns');
// when a category is removed delete the new box
add_filter('deleted_term_taxonomy', 'remove_Category_Extras');
function remove_Category_Extras($term_id) {
if($_POST['taxonomy'] == 'category'):
$tag_extra_fields = get_option(Category_Extras);
unset($tag_extra_fields[$term_id]);
update_option(Category_Extras, $tag_extra_fields);
endif;
}
I’ve sent a request to be hosted in the official WordPress repository and will post the link below if it’s accepted. Using the plugin rather than code will mean that you are automatically notified of any updates.
There’s a couple of tweaks I need to do and I also want to add code to only display the description on the first page of the category archives rather than every page.
Update 7th January 2012.
I have released CategoryTinymce V1.1, this version extends the plugin to include tag description and admin pages. There have been no issues raised with the 1.0 version so I thought it was time to extend it’s functions.
The next version will look at controling the display of the description to the first page of category or tag listings so that you don’t have too many issues with on site duplicate content. Until I include it in the plugin you can add the following code to do this.
In your category.php theme file add the following code to just before get template part call:
if (is_category() && $paged < 2) {
echo '
<p>'.category_description().'</p>';
}
and in your tag.php theme file add the following code, again just before the get template part call:
if (is_tag() && $paged < 2) {
echo '
<p>'.tag_description().'</p>';
}
Update 11th January:
There was an issue with the original code that I have now changed. The problem was that the filtering of the admin page meant that the ability to assign parent categories was lost. This has now been rectified and the code is sound.
Update: 18th February 2012.
This is the code for version 1.4 if you want to paste it as an actual function in your own functions.php file. Remember that doing it that way means you don’t get notified of ongoing updates and you could miss out.
Version 1.4 below tackles the issue of losing the parent categories box and has also been expanded to add tinymce to taxonomy and tags etc.
// lets remove the html filtering
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );
// add extra css to display quicktags correctly
add_action( 'admin_print_styles', 'categorytinymce_admin_head' );
function categorytinymce_admin_head() { ?>
<style type="text/css">
.quicktags-toolbar input{width: 55px !important;}
</style>
<?php }
// lets add our new cat description box
define('description1', 'Category_Description_option');
add_filter('edit_category_form_fields', 'description1');
function description1($tag) {
$tag_extra_fields = get_option(description1);
?>
<table>
<tr>
<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 ), 'description1', $settings); ?>
<br />
<span><?php _e('The description is not prominent by default, however some themes may show it.'); ?></span>
</td>
</tr>
</table>
<?php
}
// lets add our new tag description box
define('description2', 'Tag_Description_option');
add_filter('edit_tag_form_fields', 'description2');
function description2($tag) {
$tag_extra_fields = get_option(description1);
?>
<table>
<tr>
<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 ), 'description2', $settings); ?>
<br />
<span><?php _e('The description is not prominent by default, however some themes may show it.'); ?></span>
</td>
</tr>
</table>
<?php
}
// quick jquery to hide the default cat description box
function hide_category_description() {
global $current_screen;
if ( $current_screen->id == 'edit-category' ) {
?>
<script type="text/javascript">
jQuery(function($) {
$('select#parent').closest('tr.form-field').hide(); $('textarea#description, textarea#tag-description').closest('tr.form-field').hide();
});
</script> <?php
}
}
// quick jquery to hide the default tag description box
function hide_tag_description() {
global $current_screen;
if ( $current_screen->id == 'edit-'.$current_screen->taxonomy ) {
?>
<script type="text/javascript">
jQuery(function($) {
$('select#parent').closest('tr.form-field').hide(); $('textarea#description, textarea#tag-description').closest('tr.form-field').hide();
});
</script> <?php
}
}
// lets hide the cat description from the category admin page
add_action('admin_head', 'hide_category_description');
add_action('admin_head', 'hide_tag_description');
function manage_my_category_columns($columns)
{
// only edit the columns on the current taxonomy
if ( !isset($_GET['taxonomy']) || $_GET['taxonomy'] != 'category' )
return $columns;
// unset the description columns
if ( $posts = $columns['description'] ){ unset($columns['description']); }
return $columns;
}
add_filter('manage_edit-category_columns','manage_my_category_columns');
function manage_my_tag_columns($columns)
{
// only edit the columns on the current taxonomy
if ( !isset($_GET['taxonomy']) || $_GET['taxonomy'] != 'post_tag' )
return $columns;
// unset the description columns
if ( $posts = $columns['description'] ){ unset($columns['description']); }
return $columns;
}
add_filter('manage_edit-post_tag_columns','manage_my_tag_columns');
// when a category is removed delete the new box
add_filter('deleted_term_taxonomy', 'remove_Category_Extras');
function remove_Category_Extras($term_id) {
if($_POST['taxonomy'] == 'category'):
$tag_extra_fields = get_option(Category_Extras);
unset($tag_extra_fields[$term_id]);
update_option(Category_Extras, $tag_extra_fields);
endif;
}
To be kept up to date with all the changes it is advised to use this as a plugin rather than using the code in your functions file.
Download CategoryTinymce from the official WordPress directory.
Support plugin development with a donation:




Thank Yoo, very,very,very much.
I looked for it 5 days…
Thank you! This is (almost) exactly what I’ve been looking for!
Only difference is; I need it for Tag descriptions, not Category descriptions.
I edited the plugin source and simply replaced all instances of “Category” or “category” with “Tag” or “tag”. Not sure if that’s going to break anything, but it seems to do the job.
Only thing is; the Description Column is still visible on the Tag Admin page. Any idea why?
Cheers,
- Chris
Hi Chris
thanks for the comment.
I will be lauching an update of this plugin over the weekend (hopefully) as I’ve been asked to include tags as well as categories by others.
You should be able to get rid of the description in the tag screen by changing the taxonomy type to tags or possibly terms. I’m not too sure yet until I start the upgrade.
But great you found it useful
Kevin
Hi Chris
the taxonomy type you are looking for is post_tag in order to hide the column on the tag admin screen. Juat use this piece of code to hide the description column:
function manage_my_tag_columns($columns)
{
// only edit the columns on the current taxonomy
if ( !isset($_GET['taxonomy']) || $_GET['taxonomy'] != ‘post_tag’ )
return $columns;
// unset the description columns
if ( $posts = $columns['description'] ){ unset($columns['description']); }
return $columns;
}
add_filter(‘manage_edit-post_tag_columns’,'manage_my_tag_columns’);
Kevin
Hey, thanks for the great Plugin, it works great. Installed it on a production site and it works great, better than the other ones tested.
Maybe you have time to add possibilities for multiple visual category/tag descriptions and an extension for (custom) taxonomies? Than the Plugin would be really outstanding. But it is just a suggestion for the future
Hi thanks for the comment.
custom taxonomies is something possible for the future when I have time.
I’m not sure I understan you request for multiple visual categories though. could you explain a bit moe?
thanks
kevin
Hi Kevin,
Great plugin, thanks very much for it.
I have two suggestions for improvements it if you would appreciate the feedback:
1. Complete support for custom taxonomies. Currently, it works perfectly with custom taxonomies, however the old “Description” box is still shown on the editing page. As long as the user ignores the old box, there is no problem.
2. Don’t remove the Description column in the admin view. Users can always turn it off via “Screen options” if they like (currently they have no choice). Maybe a more elegant way would be to run a filter over the Description HTML and remove all the tags, then truncate the text to e.g. 10 words? Similar to a WP Excerpt.
Thanks again,
Lloyd
Hi Lloyd
Thanks for the comment.
Regarding point 2 I put the coding in to remove the descriptions from the admin panel because in wp 3.3 it was not happening through the screen options, I guess it’s one of the bugs they sorted out with the 3.3.1 update.
With the first point. I’ll take a look at re-writing the plugin and try and make the taxonomy type and category type dynamically called. At the moment the actual type of taxonomy is being called by name for the jquery to run on that particular page.
It is fairly straightforward to do it your self though by adding a function to filter out the box.
Either add to your own themes functions file (best to prevent it being over written by any updates I do to the plugin) or add to the categorytinymce file (After line 122) the following:
function hide_XXXX_description() {
global $current_screen;
if ( $current_screen->id == 'edit-XXXX' ) {
?>
jQuery(function($) {
$('select#parent').closest('tr.form-field').hide(); $('textarea#description, textarea#tag-description').closest('tr.form-field').hide();
});
<?php
}
}
The XXXX will depend on your taxonomy name so using countries as a taxonomy type you would probable name your filter:
function hide_countries_description()
your current screen id can be found by going to the edit page for your custom category type and looking in the url. You will see a variable called taxonomy=XXXX
This is what you want to use as the edit id in the
if ( $current_screen->id == ‘edit-XXXX’ )
so it could look something like;
if ( $current_screen->id == ‘edit-post_country’ )
or
if ( $current_screen->id == ‘edit-country’ )
Just copy the id to the edit- call and you’ll filter out the default box.
thanks
Kevin
Hey Kevin,
Thanks for the reply and the detailed instructions!
Cheers,
Lloyd
It’s a great plugin. The only problem – the pull-down-menu for editing the parent categoery has gone. Maybe there will be a fix for this?
Hi Fox-didl
I’m assuming you’ve cut and pasted the code above into your functions file rather than installed the plugin from WordPress directly. The plugin is now on version 1.4 so I suppose I should up date the code above which is the first version.
In fact I’ll do it know so give me a few minutes…..