- $p = '<p class="attachment">';
- // show the medium sized image representation of the attachment if available, and link to the raw file
- $p .= wp_get_attachment_link(0, 'medium', false);
- $p .= '</p>';
- $p = apply_filters('prepend_attachment', $p);
+ if ( 0 === strpos( $post->post_mime_type, 'video' ) ) {
+ $meta = wp_get_attachment_metadata( get_the_ID() );
+ $atts = array( 'src' => wp_get_attachment_url() );
+ if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
+ $atts['width'] = (int) $meta['width'];
+ $atts['height'] = (int) $meta['height'];
+ }
+ $p = wp_video_shortcode( $atts );
+ } elseif ( 0 === strpos( $post->post_mime_type, 'audio' ) ) {
+ $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
+ } else {
+ $p = '<p class="attachment">';
+ // show the medium sized image representation of the attachment if available, and link to the raw file
+ $p .= wp_get_attachment_link(0, 'medium', false);
+ $p .= '</p>';
+ }
+
+ /**
+ * Filter the attachment markup to be prepended to the post content.
+ *
+ * @since 2.0.0
+ *
+ * @see prepend_attachment()
+ *
+ * @param string $p The attachment HTML output.
+ */
+ $p = apply_filters( 'prepend_attachment', $p );