This topic contains 14 reply and 6 voices, and was last updated by Tareq Hasan 6 years, 3 months ago
Viewing 14 Posts - 1 through 14 (of 14 total)
Author Posts
June 3, 2013 at 11:47 pm 4523
Tareq Hasan I created a URL field for a link to a YouTube Video. It displays the text of the link when I include this in the single.php ID, 'you_tube_link', true ); ?> How can I get to embed and auto display the video rather than just show the text of the link?
June 4, 2013 at 12:51 am 4525
paperweight paperweight

Check this page:

Maybe wrap it in shortcode to display? For example does this work, or something like it?
[embed]< ?php echo get_post_meta( $post->ID, ‘you_tube_link’, true ); ?>[/embed]

June 4, 2013 at 1:38 am 4526
LJA32118 LJA32118

Tried that and it prints out the following:


and on those that don’t have a YouTube link it prints out:


I checked out that WordPress Page plus about every other page about embedding a YouTube video in the single.php

It works if it is included in the Post Body but not as a field unto itself.

June 4, 2013 at 4:04 pm 4542
paperweight paperweight

Then I’m unclear too — maybe try to make sure it’s wrapped in the Loop? I’d like to know how you finally find a solution~

June 5, 2013 at 10:52 am 4579
Webfreelance Webfreelance

Simple solution!
Install this plugin

Create a custom field called youtubeid and on the input side only put the video id.
EG: – only the bolded part.

Then write a function to display the output, add this in your page template.

$tubeid =  get_field('youtubeid'); // The parameter name 
$newTubeid = $tubeid;// appending the values

Place this in your template where you want the video to show.

<?php do_shortcode('[lyte id="'.$newTubeid.'" /]'); ?>

June 5, 2013 at 11:11 am 4581
Webfreelance Webfreelance

Because you are using wp userfrontend pro your function should be this.

$tubeid =  get_post_meta( $post->ID, ‘youtubeid’, true ); // The parameter name 
$newTubeid = $tubeid;// appending the values
June 5, 2013 at 11:14 am 4582
Webfreelance Webfreelance

If you are going to make this function work for multiple youtube videos then put the function in your loop below <?php while (have_posts()) : the_post(); ?> then the this outside the loop <?php do_shortcode('[lyte id="'.$newTubeid.'" /]'); ?>

The each time you input a video id for individual posts it will show the id specific video on the post 🙂

June 5, 2013 at 1:20 pm 4584
LJA32118 LJA32118

For some reason – this did not work for me in my single.php – I did put it inside the loop.

If I include a YouTube link inside the “content” it works fine. I tried creating a textarea (with RichText turned off) and using that for the link, but it did not work – it just displayed the link url.

June 5, 2013 at 2:36 pm 4585
Tareq Hasan Tareq Hasan

Try this:

<?php echo wp_oembed_get( get_post_meta($post->ID, ‘you_tube_link’, true) ); ?>

June 5, 2013 at 3:22 pm 4586
LJA32118 LJA32118

Works perfectly – thanks again!

June 5, 2013 at 3:57 pm 4587
paperweight paperweight

Yes, seems to work well with oembed 🙂

July 5, 2013 at 3:16 pm 5617
onafets onafets

sorry, I need to get this thing work,

this is what I append to my function.php

function wpuf_youtubeid( $post_id ) {
$tubeid =  get_post_meta( $post->ID, ‘youtubeid’, true ); // The parameter name 
$newTubeid = $tubeid;// appending the values

and this in my single.php
<?php echo wp_oembed_get( get_post_meta($post->ID, 'you_tube_link', true) ); ?>

In the form I add a custom TEXT FIELD for the youtube id

Is it all right?
It doesn’t work for me.

July 5, 2013 at 3:44 pm 5619
Mahi Mahi


when you put <?php echo wp_oembed_get( get_post_meta($post->ID, 'you_tube_link', true) ); ?>

make sure your yourtube custom field meta key is – you_tube_link

does it makes sense ?

July 5, 2013 at 4:19 pm 5621
onafets onafets

Sorry, I don’t think to follow, do you mean this:

I have this doubt, shall I create a new custom post type or is the plugin wp youtube lyte that makes all of it

July 6, 2013 at 5:59 pm 5636
Tareq Hasan Tareq Hasan

You don’t need to create any function. Just make sure you have a full youtube video URL in that custom field and it should work.

Viewing 14 Posts - 1 through 14 (of 14 total)