WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using [video] as featured image or through custom field (2 posts)

  1. UnderABrightSky
    Member
    Posted 1 year ago #

    Hope it's the right forum - not sure...

    I've been testing the new MediaElement.js-powered [Video]-element, and I really like it!

    I wonder if it's possible to use it, so a html5 video is shown as the featured image on the posts? I'm all into highly customizing my theme with ninja-code in functions.php, but no core-hacking.

    Or could a custom field be used to associate a video to a specific part of the post layout?

    I tried to use a custom field, but if there's no [video]-elements on the webpage, it seems to be missing those:

    wp-includes/js/mediaelement/mediaelementplayer.css
    wp-includes/js/mediaelement/wp-mediaelement.css
    wp-includes/js/mediaelement/mediaelement-and-player.js
    wp-includes/js/mediaelement/wp-mediaelement.js

    Otherwise it seems doable.

    My questions:

    1) Is [video] as featured image (or reachable via custom field) something there's in the works for 3.6? Or on the roadmap for 3.x?

    2) Is this a far-fetched approach - or is it nearby with a bit of ninjaing?

    3) Any other suggestions on getting a html5-video in - not as part of the blog-text, but as a separate element in the design.

    I've searched and searched on documentation and ways to go with this, but no luck - probably because it's still in production. Any help or comments would be highly, highly valued! :-)

  2. I believe the function you're looking for is wp_video_shortcode() in wp-includes/media.php. It's the display callback for the [video] shortcode and also handles enqueueing Mediaelement.js. The earliest you can use it is on the init hook, in other words, you should have to no problem using it on the front-end.

    It takes an array of four attributes:

    1. src
    2. poster
    3. height (int)
    4. width (as determined by the value of $content_width)

    There would be two ways to implement it

    1. With the display callback:
      $video = wp_video_shortcode( array(
      	'src' => 'http://somevideourl.mp4',
      	'poster' => '',
      	'height' => 604,
      	'width' => 300
      ) );
      echo $video;
    2. With the shortcode:
      >> Using post meta
      echo do_shortcode( get_post_meta( get_the_ID(), 'your_video_custom_field', true ) );
      >> or directly
      echo do_shortcode( '[video mp4="http://somevideourl.mp4" height="300" width="604"]' );

    For your special use case of using as a featured image, that would have to be some kind of custom implementation on your part. The above examples should get you started though.

Topic Closed

This topic has been closed to new replies.

About this Topic