• Hey everybody, I’ve been scratching my head about this one for a few days, so I hope someone call help me figure this out.

    I’m trying to create a shortcode that will embed videos inline. My videos are hosted at Amazon S3. I’ve created a custom field (using the Advanced Custom Fields plugin) for each video to input a URL to that video. Then, I pull in the URLs and embed them using WordPress’s built-in oEmbed.

    A (simplified version of my code can be seen below:

    function locked_videos( $atts ) {
    	extract( shortcode_atts( array(
    		'id' => ''
    	), $atts ) );
    	global $post;
    	global $wp_embed;
    
    	//Advanced Custom Field's way of getting post metadata
    	$vids = get_field('vids', $post->ID);
    
    	$videos = '<div class="videos">';
    		if ($vids) {
    			foreach($vids as $vid) {
    				$videos .= $wp_embed->run_shortcode('[embed width="600"]' . $vid['video_url'] . '[/embed]');
    			}
    		}
    	$videos .= '</div>';
    	return $videos;
    }

    It works fine for Vimeo and YouTube videos, but when I try to add Amazon S3 videos, it just outputs the shortcode like this and displays it on the page:

    [video src="https://s3.amazonaws.com/path/to/my/video.mp4" /]

    Even though, if just put the same code into the WYSIWYG editor Everything works fine and the video embeds:

    [embed width="600"]https://s3.amazonaws.com/path/to/my/video.mp4[/embed]

    I’ve tried adding Amazon as an oEmbed provider using the following code, but maybe my syntax is wrong?

    add_action( 'init', 'add_oembed_handlers' );
    function add_oembed_handlers() {
    	wp_oembed_add_provider( '#https?://(www\.)?amazonaws.com/.*#i', 'http://s3.amazonaws.com', true );
    }

    But then why would it work with the straight up embed? Does anybody have any ideas as to what might be happening? Any help provided would be much appreciated. Thanks!

  • The topic ‘Adding Amazon S3 as oEmbed provider?’ is closed to new replies.