I'm creating a film portfolio and I have created the custom post type for portfolio items with a field for the Vimeo link. WordPress is not automatically embedding Vimeo links when I echo the url onto the page and is instead the url is displaying as plain text. I've tested by creating a post with the video link and that is auto-embedding just fine. Heres the code I'm using:
<?php echo get_post_meta(get_the_ID(), 'vimeo_link', TRUE); ?>
If I'm not mistaken, WordPress doesn't oEmbed inside of actual theme files. Instead, you'll need to do something like this
if (get_post_meta($wp_query->post->ID, 'vimeo_link', true) != '') {
<iframe src="<?php echo get_post_meta(get_the_ID(), 'vimeo_link', TRUE); ?>?title=0&byline=0&portrait=0" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
}
if statement reference
Related
Ive got a form, where users can add videos to a profile field. What I am trying to do is make the video auto play. However Im struggling with youtube url, I know most users will just copy the URL from their browser.
So ive got this
<iframe src="<?php echo get_post_meta( get_the_ID(), 'wpcf-item-video', true ); ?>" frameborder="0" gesture="media" allowfullscreen=""></iframe>
It fetches the url fine
for example
https://www.youtube.com/watch?v=SabxJ0nqKlE
Now I need to turn the watch?v= to /embed/
Any advice on how I can accomplish this please
you can do
<?php
$url = get_post_meta( get_the_ID(), 'wpcf-item-video', true );
$my_var = '/embed/';
$url = str_replace("watch?v=", $my_var, $url );
?>
<iframe src="<?php echo $url ?>" frameborder="0" gesture="media" allowfullscreen=""></iframe>
You can use str_replace just do this:
str_replace('watch?v=', '/embed/', $myUrl)
then put the url in the frame
I want to wrap decode all html tags from a post content in Wordpress.
like
<iframe src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2FRocketsAreCool%2Fvideos%2F1032994553496742%2F&show_text=0&width=560" width="560" height="315" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allowFullScreen="true">
When I try this code:
$query = new WP_Query(array('name'=>'example_topic'));
$post = $query->posts;
$text = htmlspecialchars_decode($post->content);
It works, but not closing the html tag because the tag was not originally closed in the encoded tags, so every thing comes after not showing in browser.
I am trying to create where people can input a video url and it will save into my database. The thing is that after I've saved the video url in my database, how can I show it on the page using PHP?
For example, using this embedded vimeo video, how can I display it after I've called it from my database.
If I want to show it from the database like this:
$result = mysqli_query($connect,"SELECT * FROM web where video <> '' && video IS NOT NULL");
if ($row = mysqli_fetch_array($result))
{
How can I display this?
<iframe src="https://player.vimeo.com/video/90312869" width="500" height="281"
frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen>
</iframe>
<p><a href="https://vimeo.com/90312869">360°
Video using 6 GoPro Cameras - spherical panorama timelapse</a>
from j0n4s on Vimeo.</p>
Like this:
$result = mysqli_query($connect,"SELECT * FROM web where video <> '' && video IS NOT NULL");
if ($row = mysqli_fetch_array($result))
{
$url = $row['url'];
}
<iframe src="<?php echo $url; ?>" width="500" height="281"
frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<p><a href="<?php echo $url; ?>">360°
Video using 6 GoPro Cameras - spherical panorama timelapse</a>
from j0n4s on Vimeo.</p>
in html 5 I would write it like this
<?php
// get the url
$sourceURL = value of the extracted column from your table which is a url;
//Extract the file name
$fileName = new SplFileInfo::getFilename ( $sourceURL );
// Get the file extention
$fileExtention = new SplFileInfo::getExtension ( $fileName );
$sourceHTML = '<source src='.$sourceURL.' type="video/'.$fileExtention.'">';
?>
<video width="400" controls>
<?php echo $sourceHTML; ?>
Your browser does not support HTML5 video.
</video>
I'm trying to pull out the video thumbnail from the TED video embed code. Why? Well, I'm using a WordPress theme that uses a custom field to handle video but the thumbnail function for that field isn't built for TED. I'm trying to re-jig it.
Here's the video thumbnail retrieval function (where YouTube and Vimeo are covered):
function woo_get_video_image($embed) {
$video_thumb = '';
/* Let's start by looking for YouTube, then Vimeo */
if ( preg_match( '/youtube/', $embed ) ) {
// YouTube - get the video code if this is an embed code (old embed)
preg_match( '/youtube\.com\/v\/([\w\-]+)/', $embed, $match);
// YouTube - if old embed returned an empty ID, try capuring the ID from the new iframe embed
if( !isset($match[1]) )
preg_match( '/youtube\.com\/embed\/([\w\-]+)/', $embed, $match);
// YouTube - if it is not an embed code, get the video code from the youtube URL
if( !isset($match[1]) )
preg_match( '/v\=(.+)&/',$embed ,$match);
// YouTube - get the corresponding thumbnail images
if( isset($match[1]) )
$video_thumb = "http://img.youtube.com/vi/".$match[1]."/0.jpg";
} else if ( preg_match( '/vimeo/', $embed ) ) {
// Vimeo - get the video thumbnail
preg_match( '#http://player.vimeo.com/video/([0-9]+)#s', $embed, $match );
if ( isset($match[1]) ) {
$video_id = $match[1];
// Try to get a thumbnail from Vimeo
$get_vimeo_thumb = unserialize(file_get_contents_curl('http://vimeo.com/api/v2/video/'. $video_id .'.php'));
$video_thumb = $get_vimeo_thumb[0]['thumbnail_large'];
}
}
// return whichever thumbnail image you would like to retrieve
return $video_thumb;
}
Here's a typical TED embed:
<iframe
src="http://embed.ted.com/talks/andy_puddicombe_all_it_takes_is_10_mindful_minutes.html"
width="560" height="315"
frameborder="0"
scrolling="no"
webkitAllowFullScreen mozallowfullscreen allowFullScreen>
</iframe>
And the TED API docs if that helps at all: http://developer.ted.com/API_Docs
I seem to be having trouble customizing the preg_match and/or $get_vimeo_thumb portions (at least that's what I think is going on). Basically, I'm learning this portion of PHP and it's bumpy.
you can try this
$source = 'http://www.ted.com/talks/andy_puddicombe_all_it_takes_is_10_mindful_minutes';
$tedJson = json_decode(file_get_contents('http://www.ted.com/talks/oembed.json?url='.urlencode($source)), TRUE);
pr($tedJson);
you will get the json in responce
I don't know what possessed me to answer this question, but here is a (tested working) quick and dirty. You'll probably want to throw some validation in there somewhere.. And if I were getting paid to do this it wouldn't be using file_get_contents and I'd probably use DOMDocument.
$embed = '<iframe
src="http://embed.ted.com/talks/andy_puddicombe_all_it_takes_is_10_mindful_minutes.html"
width="560" height="315"
frameborder="0"
scrolling="no"
webkitAllowFullScreen mozallowfullscreen allowFullScreen>
</iframe>';
function getThumbnail($embed){
preg_match("/src\=\"(.+)?\"/", $embed, $matches);
$uri = $matches[1];
preg_match("/posterUrl\s=\s\'(.+)?\'/", file_get_contents($uri), $matches);
echo $matches[1];
}
getThumbnail($embed);
We are taking the src of the iframe, getting the contents, and scrapping the JS embed variable to grab the image they use for the thumbnail.
Obviously you won't echo the output, and who knows if this is against their TOS. As a matter of fact I'd bet they at least wouldn't let you use this unless you kept the logo (which is not the case). Use at your own risk.
I want to replace in post and archive custom field the youtube url with php.
From: http://www.youtube.com/watch?v=FKAjQfL31Dw To:
http://www.youtube.com/v/FKAjQfL31Dw
My code is:
<?php if ( get_post_meta($post->ID, 'ixosrip', true) ) { ?>
<embed style="width:150px;height:25px;" allowfullscreen="false" type="application/x-shockwave-flash" src="http://www.youtube.com/v/<?php echo get_post_meta($post->ID, "ixosrip", $single = true); ?>&ap=%2526fmt%3D18&autoplay=0&rel=0&fs=1&color1=0xC0C0C0&color2=0xFFFFFF&border=0&loop=0">
<?php } else { ?>
<em>No sound</em>
<?php } ?>
Current i use a javascript, taked from here: find all youtube links with js (jquery) / But its loads very slow my site.
Is there any way to do this with php in the custom field?
Thank you.
David.
If you can iterate over your custom fields, just do it with a simple PHP str_replace:
$new_url = str_replace('/watch?v=', '/v/', $old_url);
Where $old_url is your video's current slug.
UPDATED ANSWER: You could parse the URL, grabbing the v component:
parse_str($video_url, $params);
$video_id = $params['v'];
$video_url = 'http://www.youtube.com/v/'.$video_id;
You would put this in your loop or your post page template or whatever, where $video_url is the field containing, well, the YouTube video URL you want to alter.
Aye there,
One thing I can think of is making 2 custom fields where one would be the id and would have a value like 'FKAjQfL31Dw'
...and the other would have a value of either 'v/' or 'watch?v=' depending on which one u choose. (can be done via radio buttons)
so ur code might look something like
<embed style="width:150px;height:25px;" allowfullscreen="false" type="application/x-shockwave-flash" src="http://www.youtube.com/
<?php $key='youtube_format'; echo get_post_meta($post->ID, $key, true); ?>
<?php $key='youtube_id'; echo get_post_meta($post->ID, $key, true); ?>
&ap=%2526fmt%3D18&autoplay=0&rel=0&fs=1&color1=0xC0C0C0&color2=0xFFFFFF&border=0&loop=0">
If your trying to do this in archives, you would most likely add this code to content.php or content-video.php.