Notifications
Clear all

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.

 

[Solved] How to insert youtube link?

4 Posts
3 Users
0 Reactions
5,706 Views
enricocantori
Posts: 16
Topic starter
(@enricocantori)
Eminent Member
Joined: 7 years ago
3 Replies
Sofy
Posts: 5483
 Sofy
Admin
(@sofy)
Support Team
Joined: 8 years ago

Just put this code in active WordPress theme's functions.php:

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, "<iframe width=\"420\" height=\"280\" src=\"//www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen></iframe>", $content);
return $content;
}

Also, check out this paid addon:

https://gvectors.com/product/wpforo-embeds/

2 Replies
(@synergy)
Joined: 5 years ago

Eminent Member
Posts: 16

@sofy

i think i like the embed addon and will purchase it soon. But at the main time, i want to use the alternate option you provided with the Code but it seems not working for me

I added it with my snippet plugin, deleted all caches, pressed ctrl+f5 in front end. I then login as registered user, copied a Youtube link and pasted as a comment, it just appeared as I pasted. what did i miss please

 

Sofy
 Sofy
Admin
(@sofy)
Joined: 8 years ago

Support Team
Posts: 5483

@synergy

We've just checked the code, it works fine.Β 

Please make sure the code you've entered is correct and the code is pasted in the current active theme functions.php file.Β 

Β Here is an instruction on How to Edit Your Theme’s Functions.php File Without Killing Your Site:

https://www.nosegraze.com/edit-functions-php/