do_action( “{$taxonomy}_edit_form_fields”, WP_Term $tag, string $taxonomy )

Fires after the Edit Term form fields are displayed.

Description

The dynamic portion of the hook name, $taxonomy, refers to the taxonomy slug.

Possible hook names include:

  • category_edit_form_fields
  • post_tag_edit_form_fields

Parameters

$tagWP_Term
Current taxonomy term object.
$taxonomystring
Current taxonomy slug.

Source

do_action( "{$taxonomy}_edit_form_fields", $tag, $taxonomy );

Changelog

VersionDescription
3.0.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    Adding custom meta fields to a taxonomy.

    Note that in this example name of the input is set to be an array. If the field name was not an array, then you’d have to save each field individually.

    // Key of your custom taxonomy goes here.
    // Taxonomy key, must not exceed 32 characters.
    $prefix_taxonomy = 'category';
    
    /**
     * This will add the custom meta field to the add new term page.
     *
     * @return void
     */
    function wporg_prefix_add_meta_fields() {
    	?>
    
    	<div class="form-field term-meta-wrap">
    		<label for="term_meta[custom_term_meta]">
    			<?php esc_html_e( 'Example meta field', 'textdomain' ); ?>
    		</label>
    		<input type="text" name="term_meta[custom_term_meta]" id="term_meta[custom_term_meta]" value="" />
    		<p class="description">
    			<?php esc_html_e( 'Enter a value for this field.', 'textdomain' ); ?>
    		</p>
    	</div>
    	
    	<?php
    }
    add_action( sprintf( '%s_add_form_fields', $prefix_taxonomy ), 'wporg_prefix_add_meta_fields' );
  2. Skip to note 4 content

    Adding WP editor to default description field:

    /**
     * Default taxonomy description field using WP editor
     *
     * @link    https://codex.wordpress.org/Javascript_Reference/wp.editor
     * @return  void
     */
    function html_taxonomy_description()
    {
    	?>
    	
    		jQuery(document).ready(function($) {
    			let field = 'tag-description';
    			if ( document.getElementById(field) == undefined ) {
    				field = 'description';
    			}
    
    			wp.editor.initialize(field, {
    				tinymce: {
    					toolbar1: 'formatselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link',
    					plugins: 'link,lists,textcolor,colorpicker',
    					menubar: false,
    					statusbar: false,
    				},
    				quicktags: true,
    				mediaButtons: false,
    			});
    
    			$('#submit').mousedown( e => {
    				console.debug('submit.mousedown', e);
    				e.preventDefault();
    	
    				tinyMCE.triggerSave();
    	
    				$(e.currentTarget).trigger('click');
    			});
    		});
    	
    	<?php
    }
    add_action( "{$taxonomy}_edit_form_fields", 'html_taxonomy_description' );
    add_action( "{$taxonomy}_add_form_fields", 'html_taxonomy_description' );
    
    /**
     * Loading editor assets
     *
     * @return  void
     */
    function wp_editor_includes()
    {
        global $pagenow, $current_screen;
    
        if ( in_array($pagenow, array('edit-tags.php', 'term.php')) )
    	{
    		wp_enqueue_editor();
    		wp_enqueue_media();
    	}
    }
    add_action( 'init', 'wp_editor_includes' );

You must log in before being able to contribute a note or feedback.