Support » Developing with WordPress » Issue displaying video from custom meta

  • I am having an issue displaying locally hosted video and youtube/vimeo videos from a custom meta field. I was originally using

    <?php echo apply_filters(‘the_content’ get_post_meta($post->ID, 'video_field', true)); ?>

    It works great for outputting the videos, however this breaks many plugins due to the_content call. My page builder for example doesn’t display in the correct area due to this call (Same with social sharing links and a few other plugins).

    I also tried creating a custom apply_filters call but it didn’t seem to work either. Perhaps I’m missing some filter?

    Lastly, I also tried using
    <?php echo wp_oembed_get(get_post_meta($post->ID, 'video_field', true) ); ?>

    This works great for oembeds like youtube and vimeo. However it does NOT work for locally hosted videos.

    Any solution for displaying locally hosted videos AND youtube/vimeo from a custom meta field?

Viewing 4 replies - 1 through 4 (of 4 total)
  • WordPress will only embed URLs matching an internal whitelist. This is for security purposes.

    You can change this:

    Thread Starter ProgressionStudios


    Thanks for the reply.

    What I need is to paste a video link like so in a custom meta field:

    Then have it output the video. This works when using
    <?php echo apply_filters(‘the_content’ get_post_meta($post->ID, 'video_field', true)); ?>

    However I need to figure out how to do this without using the_content call as it breaks many plugins that look for this line. Any filters I can use for this that work with locally hosted videos? I know this is possible since it works with the_content call but I haven’t found a solution after searching online.

    WordPress embeds locally hosted videos using ‘[video]‘ shortcode,
    So you can achieve what you want by doing something like this:

    		$videoURL = get_post_meta($post->ID, 'video_field', true);
    		$oEmbed = wp_oembed_get( $videoURL );
    		if ( $oEmbed != false ) {
    			echo $oEmbed;
    		} else {
    			echo do_shortcode( '[video src="' . $videoURL . '"]' );
    Thread Starter ProgressionStudios


    Thanks for the example! This should make for an okay work-around but it still limits many examples and options.

    Ideally there would be a way to replicate the functionality of
    <?php echo apply_filters(‘the_content’ get_post_meta($post->ID, 'video_field', true)); ?>
    but with a custom filter so I don’t have to use the_content. The above solution works for oembeds, .mp4 links, and manually adding in embed code (Offering support for any third party video source). The solution above only works with ombeds and .mp4 links.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Issue displaying video from custom meta’ is closed to new replies.