Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
add_action( 'category_add_form_fields', 'baw_new_term_color_field' );
function baw_new_term_color_field() {
wp_nonce_field( 'add_term_meta_color', 'add_term_meta_color_nonce' );
<div class="form-field">
<label for="baw_term_color"><?php _e( 'Front Color', 'baw' ); ?></label>
<input type="text" name="baw_term_color" id="baw_term_color" data-default-color="#FFFFFF" value="#FFFFFF" />
add_action( 'category_edit_form_fields', 'baw_edit_term_color_field' );
function baw_edit_term_color_field( $term ) {
$color = get_term_meta( $term->term_id, 'color', true );
$color = preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ? $color : '#FFFFFF';
<tr class="form-field">
<th scope="row"><label for="baw_term_color"><?php _e( 'Front Color', 'baw' ); ?></label></th>
<?php wp_nonce_field( 'add_term_meta_color', 'add_term_meta_color_nonce' ); ?>
<input type="text" name="baw_term_color" id="baw_term_color" value="<?php echo esc_attr( $color ); ?>" data-default-color="#FFFFFF" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment