Easy YouTube embed hack (General)

by Bubba @, Saturday, November 02, 2013, 08:20 (3800 days ago)
edited by Bubba, Saturday, November 02, 2013, 08:42

I looked all over the place and couldn't find an easy way to get YouTube embedding to work. Everything I found was either going to be a pain for me to implement, or a pain for the users, or both, so I decided to come up with my own fix. This is the absolute simplest way I can think of to get YouTube embedding to work.

In the file functions.inc.php, in the function do_bbcode_flash, place the code below just after the else and before the line:

    $html = '<!--[if IE]>

The else is at line 575 in my copy and I don't think I've added any lines of code, but you can just search for the function name.


    if (strpos($content,"http://youtu.be/") !== false) {
     $content = str_replace("http://youtu.be/", "http://www.youtube.com/v/", $content);
    }

Once that is in place you can just click on the flash button and paste a video share link in the flash url box. It don't get much simpler than that :-D

I can't guaranty it will work forever, YouTube may change their urls in the future, but until then it should be good ;-)

Easy YouTube embed hack

by grognard, Friday, November 08, 2013, 18:40 (3793 days ago) @ Bubba

This works well. Thanks! :-D

it works but..

by bakunin, Tuesday, December 31, 2013, 17:01 (3741 days ago) @ Bubba

yeah it did work, and very easy to set up as you said.. however it only takes the short yt urls, and not the ordinary, at least when i tried that didnt work..

thanks for posting this, and a happy new year too

it works but..

by kittykuma, Wednesday, January 01, 2014, 03:22 (3740 days ago) @ bakunin

yeah it did work, and very easy to set up as you said.. however it only takes the short yt urls, and not the ordinary, at least when i tried that didnt work..

thanks for posting this, and a happy new year too

I tried this for normal link.

if (strpos($content,"http://www.youtube.com") !== false) {
$content = str_replace("http://www.youtube.com/watch?v=", "http://youtube.googleapis.com/v/", $content);
}

but vids only load on pc, won't load on mobile device though. anyone has better solution?

it works but..

by Bubba @, Wednesday, January 01, 2014, 15:49 (3740 days ago) @ kittykuma

You are using http://youtube.googleapis.com/v/ try http://www.youtube.com/v/ in it's place. That seems to work OK for my android tablet, I don't think anything flash based will work on ios devices, I may be wrong though, I don't have an ios device to check it with. You can see what I am talking about in my response to bakunin.

it works but..

by Bubba @, Wednesday, January 01, 2014, 15:26 (3740 days ago) @ bakunin
edited by Bubba, Wednesday, January 01, 2014, 15:46

You're welcome, I'm glad you found it useful. I had only intended for it to work with the share links, which is why I said paste a video share link in the post, I guess I should have made it clear that it would not work with the normal urls. My intent was to get the job done with the smallest amount of code possible, so the code only handled the share links and nothing else. Just add the following directly above or below the other code and it will handle the regular urls ;-)

    if (strpos($content,"http://www.youtube.com/watch?v=") !== false) {
     $content = str_replace("http://www.youtube.com/watch?v=", "http://www.youtube.com/v/", $content);
    }

Easy YouTube embed hack (Full Screen?)

by Magma, Tuesday, April 21, 2015, 12:21 (3265 days ago) @ Bubba

This works great but is there anyway to allow the YouTube video to go full screen?

The short answer is no...

by bubba, Saturday, May 02, 2015, 15:49 (3254 days ago) @ Magma

Full screen mode only works when the movie is in an i f r a m e and you'd have to bypass all the code injection protection to get it to work.

I tried responding when you posted this but the board wouldn't let me post certain words and then locked me out from posting at all. It's a tad overzealous in that department at times ;)

The short answer is no...

by Magma, Sunday, May 03, 2015, 23:39 (3252 days ago) @ bubba

Full screen mode only works when the movie is in an i f r a m e and you'd have to bypass all the code injection protection to get it to work.

I tried responding when you posted this but the board wouldn't let me post certain words and then locked me out from posting at all. It's a tad overzealous in that department at times ;)


That's a shame :-( I do thank you very much bubba for the reply considering it's an older thread. I'm just praying Google do not change stuff their end so your hack stops working :lookaround:

RSS Feed of thread