Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FrancoStino/b73a6c0b19078d319e82cf07e0f604e0 to your computer and use it in GitHub Desktop.
Save FrancoStino/b73a6c0b19078d319e82cf07e0f604e0 to your computer and use it in GitHub Desktop.
Add TinyMCE Editor to Custom Taxonomy Categories Description Field

Add TinyMCE Editor to WooCommerce Product Categories Description Field

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.

Code

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
}

Installation

  1. Copy the above code.
  2. Paste it into your theme's functions.php file or a custom plugin.

Details

  • 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.

Notes

  • 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment