function add_tags_to_attachments() { register_taxonomy_for_object_type( 'post_tag', 'attachment' ); } add_action( 'init' , 'add_tags_to_attachments' ); function category_and_tag_archives( $wp_query ) { $my_post_array = array('post','page','attachment'); if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) ) $wp_query->set( 'post_type', $my_post_array ); if ( $wp_query->get( 'tag' ) ) $wp_query->set( 'post_type', $my_post_array ); } function inserted_image_titles( $html, $id ) { $attachment = get_post($id); $thetitle = $attachment->post_title; $tags_str = ''; $tags_array = wp_get_post_tags($id); foreach ($tags_array as $tag) { $tags_str .= $tag->name.' '; } if($tags_str != '') { $tags_str = substr($tags_str, 0, strlen($tags_str)-1); } $output = str_replace('ID)->post_title; $tags_str = ''; $tags_array = wp_get_post_tags($attachment->ID); foreach ($tags_array as $tag) { $tags_str .= $tag->name.' '; } if($tags_str != '') { $tags_str = substr($tags_str, 0, strlen($tags_str)-1); } $attr['alt'] = (($attr['alt']=='')?'':$attr['alt'].' ').$tags_str; return $attr; } add_filter('wp_get_attachment_image_attributes', 'featured_image_titles', 10, 2);