I was wondering if there is any way to combine a custom field (in custom post type) with an embed shortcode? Long story short - a user type into a field called videox and an url for a video (youtube, vimeo) or audio (e.g. soundcloud). When I render this field, of course it displays as it was in the field. How do I convert such input into an embeded audio / video?

I've tried to echo that input between embed (as do_shortcode('[embed]' . $adresgoeshere . '[/embed]');) yet without success.

  • Just checking I'm understanding you. You have a CPT with two fields. User type and url and you are trying to display them with a shortcode? Also could you post all code relating to this. Thanks!
    – thebigtine
    Commented Jun 4, 2016 at 16:06

3 Answers 3


As you are using URLs from oEmbed provides (YouTube, Vimeo, Soundcloud, etc), I would use wp_oembed_get() function. This function uses oEmbed and tries to get the embed HTML of the provided URL.

$embed = wp_oembed_get( $some_url );
if( $embed ) {
   echo $embed;
} else {
   // The embed HTML couldn't be fetched

Adding another way here. You can leave this to WordPress and just pass the URL from the_content filter.


$adresgoeshere = 'URL of oembed providers'
echo apply_filters('the_content', $adresgoeshere); 

Instead of do_shortcode you can use the run_shortcode function of $wp_embed

global $wp_embed;
$embed = $wp_embed->run_shortcode( '[embed]' . $url . '[/embed]' );

echo $embed;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.