Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

edoc's avatar
Level 24

Youtube video on website

Is anyone using a Youtube video on websites?

I am currently letting users post a url of videos, and then I paste it with iframe tags.

Let me know if there is other way or better way to do it.

0 likes
8 replies
bobbybouwmann's avatar

That's the best way right now. YouTube doesn't offer anything else than that.

You also might want to look at oEmbed. It supports more video services at once. You can find some packages for it as well ;)

oEmbed: http://oembed.com/

1 like
joedawson's avatar

I use Plyr for my website Grime Archive. I just store the Video ID, for example dQw4w9WgXcQ in my database and use Plyr like this.

<div data-type="youtube" data-video-id="dQw4w9WgXcQ"></div>

The player is pretty customisable too. I actually implemented an autoplay next video like YouTube does into Grime Archive recently. Here's what the autoplay looks like - https://twitter.com/joedawsonnn/status/773637940648050689

1 like
Kemito's avatar

Personally i do not see benefit of just storing vide code id. Yes maybe in 10 000 years YouTube will change name and links won`t work but embed with full link is the simplest way to go.

1 like
martinbean's avatar

@Kemito You don’t see the benefit of storing the video ID, and instead store the full link? Does that “full link” not also include the same video ID?

The advantage of storing just the video ID is that you can then display it however you want on the front end. You’re not tied to displaying it in whatever format the embed code you’ve copied is.

For Laracasts, do you think Jeffrey’s storing a Vimeo embed tag in the database? Or just the Vimeo ID after which he’s free to display the video however he wants in a view?

2 likes
Kemito's avatar

@martinbean I dont always think what Jeffrey would think. What i think is that its too much effort put in for such feature to worry about. As i would take full link and embed the video and move on.

martinbean's avatar

@Kemito That approach is fine. Until you need to add attributes to all the embed codes on your site, or add a class name, or use a different player…

1 like
terrymedley's avatar

Absolutely! Using YouTube videos on websites is a common practice. However, instead of directly using iframe tags, consider using the YouTube API. It provides more control, better performance, and additional features like autoplay, custom player controls, and event tracking. This can enhance user experience and offer a more seamless integration.

Please or to participate in this conversation.