Code snippets for YouTube video display using ACF
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
// ==============================================
// Filter embed_oembed_html function - to add wrap around Embedded YouTube Videos for mobile responsiveness - props cubecolour http://cubecolour.co.uk
// ==============================================
add_filter('embed_oembed_html', 'cc_embed_oembed_html', 99, 4);
function cc_embed_oembed_html($html, $url, $attr, $post_id) {
return '<div class="embed-wrap">' . $html . '</div>';
}
// Finally if we've got anything - Output
if ( $video_output_html ) echo apply_filters( 'the_content', $video_output_html );
$featured_video_html = '';
if ( get_field( 'featured_video_url' ) && get_field( 'featured_video_title' ) && get_field( 'featured_video_description' ) ) {
$featured_video_html = sprintf( '[embed]%s[/embed]<h2>%s</h2>%s',
esc_url( get_field( 'featured_video_url' ) ),
sanitize_text_field( get_field( 'featured_video_title' ) ),
sanitize_text_field( get_field( 'featured_video_description' ) )
);
}