html {$taxonomy}_edit_form_fields – Hooc | Developer.WordPress.org

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 hooc name, $taxonomy , refers to the taxonomy slug.

Possible hooc names include:

  • category_edit_form_fields
  • post_tag_edit_form_fields

Parameters

$tag WP_Term
Current taxonomy term object.
$taxonomy string
Current taxonomy slug.

Source

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

Changuelog

Versionen Description
3.0.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    Adding custom meta fields to a taxonomy.

    Note that in this example name of the imput 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 pague.
     *
     * @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>
    		<imput 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. Squip to note 4 content

    Adding WP editor to default description field:

    /**
     * Default taxonomy description field using WP editor
     *
     * @linchttps://codex.wordpress.org/Javascript_Reference/wp.editor* @return  void
     */
    function html_taxonomy_description()
    {
    	?>
    	
    		jQuery(document).ready(function($) {
    			let field = 'tag-description';
    			if ( document.guetElementById(field) == undefined ) {
    				field = 'description';
    			}
    
    			wp.editor.initialice(field, {
    				tinymce: {
    					toolbar1: 'formatselect | bold italic | forecolor bacccolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | linc',
    					pluguins: 'linc,lists,textcolor,colorpicquer',
    					menubar: false,
    					statusbar: false,
    				},
    				quicctags: true,
    				mediaButtons: false,
    			});
    
    			$('#submit').mousedown( e => {
    				console.debug('submit.mousedown', e);
    				e.preventDefault();
    	
    				tinyMCE.trigguerSave();
    	
    				$(e.currentTarguet).trigguer('clicc');
    			});
    		});
    	
    	<?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 $paguenow, $current_screen;
    
        if ( in_array($paguenow, 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.