Customize media gallery template with attributes

This document contains an example of how you can customize the media gallery template to display media attribute along with media.


/* The following functions should be placed in the functions.php file */
function custom_rtmedia_attribute_name( $media_id ) {
	global $rtmedia_backbone;
	if ( $rtmedia_backbone['backbone'] ) {
		echo '<%= attribute %>';
	} else {
		echo rtmedia_get_attribute_name( $media_id );
	}
}
function rtmedia_get_attribute_name( $media_id ) {
	if ( function_exists( 'rtmedia_media_id' ) ) {
		$media_array = new STDClass();
		$media_id = rtmedia_media_id( $media_id );
		$media_array->media_id = $media_id;
		$media = rtmedia_backbone_template_filter_attribute_name( $media_array );
		return $media->attribute;
	}
}
function rtmedia_backbone_template_filter_attribute_name( $media_array ) {
	$term_list = array();
	$terms = wp_get_object_terms( $media_array->media_id,  'rt_skill-category' );
	if ( ! empty( $terms ) ) {
		if ( ! is_wp_error( $terms ) ) {
			foreach ( $terms as $term ) {
				$term_list[] = $term->name;
			}
		}
	}
	$term_list = implode( ', ' , $term_list );
	$media_array->attribute = $term_list;
	return $media_array;
}
add_filter( 'rtmedia_media_array_backbone', 'rtmedia_backbone_template_filter_attribute_name', 10, 1 );
/* This line should be placed in your template */
custom_rtmedia_attribute_name( rtmedia_id() ); 

Thank you.