Blog

Embed Youtube URLs using ACF

We use Advanced Custom Fields a lot at Convoy. We recently developed a site where we wanted to use WordPress’s native embedding with a custom field that is managed by ACF. We figured that auto embedding wouldn’t occur automatically using ACF’s get_field function, so we tried doing this instead inside of our WordPress template:

<?php echo apply_filters( 'the_content', get_field( 'youtube_link' ) ); ?>

We were surprised that the code above didn’t work (it works well for shortcode processing), but after searching a while, we came across the wp_oembed_get function:

<?php echo wp_oembed_get( get_field( 'youtube_link' ) ); ?>

The code above did exactly what we wanted. We were then able to follow Morten Rand-Hendriksen’s handy post on adding responsive videos in WordPress. We ended up creating a site that allows our client to associate Youtube videos to their products using Advanced Custom Fields and custom post types and showing all of this content within a responsive design and layout.