wp_video_shortcode example

if ( wp_attachment_is( 'video', $post ) ) {
        $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. */
if ( ! empty( $w ) && ! empty( $h ) ) {
            $attr['width']  = $w;
            $attr['height'] = $h;
        }

        $thumb_id = get_post_thumbnail_id( $attachment_id );

        if ( ! empty( $thumb_id ) ) {
            $attr['poster'] = wp_get_attachment_url( $thumb_id );
        }

        echo wp_video_shortcode( $attr );

    elseif ( isset( $thumb_url[0] ) ) :
        ?> <div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> <p id="thumbnail-head-<?php echo $attachment_id; ?>"> <img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /> </p> </div> <?php
    else :

        
if ( empty( $src ) ) {
            return;
        }

        $youtube_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#';
        $vimeo_pattern   = '#^https?://(.+\.)?vimeo\.com/.*#';

        if ( $attachment || preg_match( $youtube_pattern$src ) || preg_match( $vimeo_pattern$src ) ) {
            add_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) );

            echo wp_video_shortcode(
                array_merge(
                    $instance,
                    compact( 'src' )
                ),
                $instance['content']
            );

            remove_filter( 'wp_video_shortcode', array( $this, 'inject_video_max_width_style' ) );
        } else {
            echo $this->inject_video_max_width_style( wp_oembed_get( $src ) );
        }
    }
Home | Imprint | This part of the site doesn't use cookies.