Last active
August 29, 2015 14:05
-
-
Save floroxmar/20827163f60345dd9bc8 to your computer and use it in GitHub Desktop.
Adding Image Option in CPT Taxonomy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This function will add option to upload/attached image to a taxonomy term edit form in Genesis Framework | |
* | |
* $tax_name - must be your taxonomy name | |
*/ | |
add_action( 'admin_init', 'ja_add_taxonomy_image_options' ); | |
function ja_add_taxonomy_image_options() { | |
add_action( $tax_name.'_edit_form', 'ja_taxonomy_image_options', 10, 2 ); | |
add_action( 'admin_enqueue_scripts', 'ja_taxonomy_image_options_js' ); | |
} | |
function ja_taxonomy_image_options_js(){ | |
wp_enqueue_script('jquery'); | |
wp_enqueue_media(); | |
wp_enqueue_script('thickbox'); | |
wp_enqueue_style('thickbox'); | |
wp_enqueue_script('media-upload'); | |
wp_enqueue_script( 'zp_taxonomy_upload', get_stylesheet_directory_uri() .'/include/upload/taxonomy-upload.js', array('jquery','media-upload','thickbox') ); | |
} | |
/** | |
* Echo the image options on the taxonomy term edit form. | |
* | |
*/ | |
function ja_taxonomy_image_options( $tag, $taxonomy ) { | |
?> | |
<h3><?php _e( 'Image Option', 'text-domain' ); ?></h3> | |
<table class="form-table"> | |
<tbody> | |
<tr> | |
<th scope="row" valign="top"><?php _e( 'Upload Image', 'text-domain' ); ?></th> | |
<td> | |
<?php $thumb_src = wp_get_attachment_image_src( $tag->meta['zp_taxonomy_image'], 'thumbnail', false ); ?> | |
<div class="zp_taxonomy_image_wrap"> | |
<p><label for="zp_taxonomy_image"><?php _e( 'Upload Custom Logo.', 'text-domain' ); ?></label> | |
<input type="text" id="zp_taxonomy_image_url" class="zp_taxonomy_image_url" name="zp_taxonomy_image_url" value="<?php echo $thumb_src[0];?>" /> | |
<input type="hidden" value="<?php echo $tag->meta['zp_taxonomy_image']; ?>" name="genesis-meta[zp_taxonomy_image]" class="zp_taxonomy_image" id="zp_taxonomy_image"> | |
<input id="zp_taxonomy_image_button" class="zp_taxonomy_image_button" name="zp_taxonomy_image_button" type="button" class="button" value="<?php _e( 'Upload Logo', 'text-domain' ); ?>" /> | |
</p> | |
<div class="zp_taxonomy_image_preview"> | |
<img style="max-width:100%; width: 300px; height: auto;" src="<?php echo $thumb_src[0]; ?>" width="300" height=" auto" /> | |
</div> | |
</div> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment