Limited Support
Our team is currently on holiday, so support will be limited during this period. Response times may be slower than usual, and some inquiries may be delayed.
We appreciate your patience and understanding, and we’ll resume our usual support by the end of August.
After struggling with it:
I was finally able to auto-embed Youtube Videos FULLY RESPONSIVE. So here is what i did:
1. Installed and Activated this tiny plugin:
https://wordpress.org/plugins/youtube-widget-responsive/
2. Changed the posted snippet of code by @Robert a little bit:
add_filter('wpforo_content_after', 'wpforo_custom_video_embed', 10); function wpforo_custom_video_embed($content) { $paterns = array(); $paterns[] = "/<a[^><]+>\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i"; $paterns[] = "/<a[^><]+>\s*[a-zA-Z\/\/:\.]*youtu.be\/([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i"; $content = preg_replace($paterns, "[youtube video=\"//www.youtube.com/embed/$1\" ]", $content); return $content; }
3. NOTHING ELSE is needed, since the css and iframe are handled by the plugin of (1)
It seems to work fine for me, please check it out yourself and let me know. Also it could be expanded or a better regex maybe. I'm not an expert. @tutrix is the master of all that. And @robert of cource.
I hope i have helped.
A little better code, remove some of Youtube branding like "watch it on Youtube and some controls".
Smoother for user.
add_filter('wpforo_content_after', 'wpforo_custom_video_embed', 10); function wpforo_custom_video_embed($content) { $paterns = array(); $paterns[] = "/<a[^><]+>\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i"; $paterns[] = "/<a[^><]+>\s*[a-zA-Z\/\/:\.]*youtu.be\/([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i"; $content = preg_replace($paterns, "[youtube video=\"//www.youtube.com/embed/$1\" modestbranding=1 controls=0 ]", $content); return $content; }
Updated, removed some uneeded code.
add_filter('wpforo_content_after', 'wpforo_custom_video_embed', 10); function wpforo_custom_video_embed($content) { $paterns = array(); $paterns[] = "/<a[^><]+>\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i"; $paterns[] = "/<a[^><]+>\s*[a-zA-Z\/\/:\.]*youtu.be\/([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i"; $content = preg_replace($paterns, "[youtube video=\"$1\" modestbranding=1 controls=0 ]", $content); return $content; }