This snippet adds the TinyMCE editor to the description field of WooCommerce product categories in the WordPress admin panel. It ensures the wp_editor
is loaded and applies TinyMCE to the description field for editing product categories.
add_action( 'admin_enqueue_scripts', 'enqueue_editor_scripts' );
function enqueue_editor_scripts()
{
wp_enqueue_editor(); // Assicura che gli script di TinyMCE siano caricati
}
add_action( 'product-category_edit_form_fields', 'add_tinymce_to_description', 10, 2 );
function add_tinymce_to_description( $term, $taxonomy )
{
?>
<script>
jQuery(document).ready(function ($) {
if (typeof wp.editor !== 'undefined') {
// Rimuovi eventuali editor già inizializzati
wp.editor.remove('description');
// Inizializza l'editor TinyMCE
wp.editor.initialize('description', {
tinymce: {
toolbar1: 'formatselect | bold italic | alignleft aligncenter alignright | bullist numlist outdent indent | link',
plugins: 'link,lists',
menubar: false,
},
quicktags: true,
mediaButtons: true,
});
}
});
</script>
<?php
}
- Copy the above code.
- Paste it into your theme's
functions.php
file or a custom plugin.
-
Hooks Used:
admin_enqueue_scripts
: Ensures the TinyMCE editor scripts are loaded.product-category_edit_form_fields
: Modifies the product category edit form fields.
-
Features:
- TinyMCE editor toolbar includes formatting options, alignment controls, and lists.
- Quicktags and media buttons are enabled.
- This code is specific to WooCommerce product categories. If you need similar functionality for other taxonomies, modify the
product-category_edit_form_fields
hook accordingly. - Ensure you have WooCommerce installed and active for this snippet to work.