wp_audio_shortcode example

if ( $this->is_attachment_with_mime_type( $instance['attachment_id']$this->widget_options['mime_type'] ) ) {
            $attachment = get_post( $instance['attachment_id'] );
        }

        if ( $attachment ) {
            $src = wp_get_attachment_url( $attachment->ID );
        } else {
            $src = $instance['url'];
        }

        echo wp_audio_shortcode(
            array_merge(
                $instance,
                compact( 'src' )
            )
        );
    }

    /** * Enqueue preview scripts. * * These scripts normally are enqueued just-in-time when an audio shortcode is used. * In the customizer, however, widgets can be dynamically added and rendered via * selective refresh, and so it is important to unconditionally enqueue them in * case a widget does get added. * * @since 4.8.0 */
if ( $open ) {
            wp_image_editor( $attachment_id );
        }

        ?> </div> <?php     elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ) :

        wp_maybe_generate_attachment_metadata( $post );

        echo wp_audio_shortcode( array( 'src' => $att_url ) );

    elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ) :

        wp_maybe_generate_attachment_metadata( $post );

        $meta = wp_get_attachment_metadata( $attachment_id );
        $w    = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0;
        $h    = ! empty( $meta['height'] ) ? $meta['height'] : 0;

        if ( $h && $w < $meta['width'] ) {
            $h = round( ( $meta['height'] * $w ) / $meta['width'] );
        }
$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'];
        }
        if ( has_post_thumbnail() ) {
            $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
        }
        $p = wp_video_shortcode( $atts );
    } elseif ( wp_attachment_is( 'audio', $post ) ) {
        $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>';
    }

    /** * Filters the attachment markup to be prepended to the post content. * * @since 2.0.0 * * @see prepend_attachment() * * @param string $p The attachment HTML output. */
Home | Imprint | This part of the site doesn't use cookies.