Im trying to wrap video urls and embed code in a classed div so that I can style it. The vid code is being pulled from the custom meta value I’ve setup for the video post type. Nothing I’ve been able to find via the forum or google seems to quite answer my question.
Use case: The user either enters a youtube url into the video meta field, or they plunk in the entire embed code. Either way I need to wrap the output in some classed divs (fitvid).
Im new with WP and was hoping someone could explain: Why the urls Im passing to the_content in the code below, not being phrased by the shortcode? And what do I have to do to get it to?</p>
<p>From what I can tell, my options are either get to recognise the urls as video and do their magic — or try to do the detection myself (which is a bit beyond my reach ATM 🙂 ). </p>
<p>Here is what I have so far:</p>
<pre><code><?
$mykey_values = get_post_custom_values('_format_video_embed');
foreach ( $mykey_values as $key => $value ) {
if (!empty($value)) {
// I can get one or the other to work but not both
//$var = apply_filters('the_content', "" . $value . "
//this will only return the url – but why?
$var = apply_filters(‘the_content’, $value );
}
echo “<div id=’fitvid’>$var</div>”;
} ?>
<?php the_content(); ?>
Hey – and thanks in advance for your experience.
So I’ve never really found out why oembed urls added via
apply_filters('the_content', $output)
, are not processed while embed shortcodes are. Im still hopeful someone might shed some light on that.I really wanted to use Alex King’s post type formats UI which is why I didn’t follow David’s example.
I ended up detecting the input using strpos and substr because that seemed the most direct. If anyone knows a better way of doing it, or sees some flaw in my approach please chime in!
I wrote a very quick and simple mark-up that works — I know WordPress has a built in oEmbed system, this doesn’t follow it – at all. However, I’d be a fool not to share it if you can adapt a solution that works for me at least.
Sampled Code Notes: For this project I had to create a custom post type for
videos
so that my client could easily go in and add video posts with the Video ID from YouTube. These videos were of Houses their company had listed, and then professionally had videos shot. Their current workflow worked, and the rate of developing a video was about 5-6 weeks per, and maybe 13-15 videos per year.When I had to start this project it was my understanding then that the oEmbed wasn’t really needed for my uses, I may now in retrospect regret the decision on the argument of syntax, elegance, etc — albeit, it’s been rigid enough for this long without fail.
With that said, I also used a Custom Metabox Class to use
get_post_meta
for the ID of the video, I didn’t ever build in Validation or Sanitizing of the input in the case that a video wasn’t entered with the expectation of someone posting to a custom post type ofvideos
that they would in fact not skip this very simple step. I’m a little over-confident at times, therefore you might want to add in some of that stuff per your needsGetting Started: Create a `page-your-custom-post-type.php and put in the following:
It is important that
'post_type' => 'your-custom-post-type'
is linked to your page-your-custom-post-type.php page, otherwise it won’t know what to output. Additionally, you can add more parameters to theWP_Query array()
WP_Query WordPress Codex Page.Linking to your custom post type by default WordPress will feed this through single.php if it exists and fallback to index.php if single.php doesn’t exist. However, If you create a single-your-custom-post-type.php WordPress will use that as your
page-template
for your custom post type.oEmbed: I’m also passing these parameters to YouTube:
?version=3&rel=0&modestbranding=1&autoplay=0&controls=0
Which tell it how to style the Video Player it renders.
Closing it all up with your
wp_reset_postdata();
and you’ve got a page that will useWP_Query
to loop through 6 Posts withthe_title()
the_excerpt
and an oEmbed Video.Cheers!
This question is pretty old, but here’s what I came up with for WordPress 4.0+
WordPress oembed wants to store the oembed urls on their own line in the database with no other markup. That’s the only way it will work. Try pasting this into the “Text” tab of a page or post:
Now click back and forth between visual and text editing mode. This is where the issue comes from.
If you want make your video width responsive, try chris coyier’s method and you won’t need to wrap the iframe.