Skip Navigation

[Resolved] Field for embed youtube video

This support ticket is created 7 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 8 replies, has 3 voices.

Last updated by David 7 years, 8 months ago.

Assisted by: Serhii Salii.

Author
Posts
#421689
1.jpg

Hello!

I am trying to display an Embed Youtube video. I need that the Youtube video will be without title and without related videos at the end. The resolution: 1280 x 720 px. (Look the attached image 1)

So to do that, my idea was create a "custom field simple line". and in that please copy the embed code from youtube.

 <iframe width="1280" height="720" src="<em><u>hidden link</u></em>" frameborder="0" allowfullscreen></iframe>

It works, if I create the post from back end.

After that, I create a creed form, but when I put the iframe in the "custom field simple line", isn't work. The form don't save that field, if I put an iframe.

How can I do this? Is there another simple way to put that video without related videos at the end?

And if there are some possibility to do it only adding the youtube normal link to a custom field. And maybe in the content template put some code.

Please, help me with this. Thanks in advance.

Looking forward your reply.
Best regards.

Sebastian

#421753

Hello, Sebastian.

Thank you for contacting our support forum.

Instead of using single line for storing Youtube video URL, Have you looked at our native Embedded video custom filed.

More info:
https://toolset.com/documentation/customizing-sites-using-php/functions/#embedded-media

#421878

Yes,

But can I disable the related videos on the end in youtube. Like I sent in the images? For that I choosed the embed.

How can I do that with embed custom field?

#421931

Hello, Sebastian

Let's turn back to your string field.

You need to add iframe to the list of allowed tags for your CRED forms. By default, WordPress disables iframe from list of available tags, so:

1) Please add following code to your theme functions.php:

add_filter( 'wp_kses_allowed_html', 'esw_author_cap_filter',1,1 );

function esw_author_cap_filter( $allowedposttags ) {

//Here put your conditions, depending your context

if ( !current_user_can( 'publish_posts' ) )
return $allowedposttags;

// Here add tags and attributes you want to allow

$allowedposttags['iframe']=array(

'align' => true,
'width' => true,
'height' => true,
'frameborder' => true,
'name' => true,
'src' => true,
'id' => true,
'class' => true,
'style' => true,
'scrolling' => true,
'marginwidth' => true,
'marginheight' => true,
);
return $allowedposttags;
}

2) Then, go to Toolset > Settings > Forms > Content Filter and add iframe to list of allowed tags.

#421966

Thanks that's works! you are great!

And in your experience, there are a way to do the same but only saving in a field in my form the "youtube link" ( eg: hidden link)

And maybe for some funtion or code reemplace in the content template or something other place the iframe code?

The only thing that I need to achive is 2 things:

* Size of the iframe: 1280 x 720 px
* No related videos at the end

How can I do that, with only in a form, adding the "youtube link" on a field?

#422082

Hello, Sebastian.

You can do it in another way. We can create custom shortcode for iframe and output it with custom field you defined before.

Please add this to your theme functions.php

add_shortcode('my-youtube', 'wpv_shortcode_youtube');
function wpv_shortcode_youtube($atts, $content = null) {
		$id = '';
		$a = shortcode_atts( array(
				'width' => '1280',
				'height' => '720',
        'url' => ''
    ), $atts, 'my-youtube');

		if($a['url']){
			parse_str( parse_url( $a['url'], PHP_URL_QUERY ), $url_vars );
			$id = $url_vars['v'];
		}

		return "<iframe width='" . $a['width'] ."' height='" . $a['height'] . "' src='<em><u>hidden link</u></em>{$id}?rel=0&showinfo=0' frameborder='0' allowfullscreen></iframe>";
}

And than in View you can output embed video with this code:

[my-youtube url="[types field='youtube'][/types]"]
#422559
4.JPG
3.jpg
2.JPG
1.jpg

Wow! What a great idea!

I almost get it! Tell me what do you see wrong in the code:

I tried with two different options of custom fields:

1. "link-youtube" = The complete classic link of youtube
2. "youtube-id" = Only the youtube id.

I tried also with the types field with this outside the name of custom field: "" or with: ' ' .

Nothing works, but the iframe was get, just without ID.

Look the attached images:

1. Source code of the web page when doesn't work. The iframe is generated but without Youtube ID
2. Two different custom field to try. I don't know which is correct. I tried both.
3. Code in custom function plugin.
4. Code in Content template of Views. I tried with the two custom fields.

I love your idea, but what is wrong in my implementation?

#423084

Thank you! I could do it change something of your code help!

Thank you!!

#494018

Hi Sebastian,

This looks good. Can you share how you achieved your result?

Thanks.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.