Filter attachment_template
and return your custom path. For details, see wp-includes/template.php
, function get_query_template()
.
Sample code:
add_filter( 'attachment_template', function( $template )
{
global $post;
// inspect $post object to determine the correct template
// and change the file path, then:
return $template;
});