Notifications
Clear all

[Solved] My code is not getting embeded

15 Posts
5 Users
3 Likes
2,172 Views
mrfahadkhan
Posts: 27
Topic starter
(@mrfahadkhan)
Eminent Member
Joined: 3 years ago

Hi, i am trying to embed a youtube video via code, it show me the video preview in editor but when i post it it shows nothing.

Topic Tags
14 Replies
Sofy
Posts: 4057
 Sofy
Admin
(@sofy)
Support Team
Joined: 5 years ago

Hi @mrfahadkhan,

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;
}

For more advanced embedding options please check out wpForo Embeds add-on:

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

2 Replies
mrfahadkhan
(@mrfahadkhan)
Joined: 3 years ago

Eminent Member
Posts: 27

I have added this code at the bottom of Functions.php but still my videos are not getting embedded.

Martin
Moderator
(@martin)
Joined: 6 years ago

Support Team
Posts: 866

Please click on the [Delete all caches] button in wpForo cache in Dashboard > Forums > Dashboard admin page. Then delete website cache, then navigate to forum home page and press Ctrl+F5. If it doesn't help, leave some example URL, where we can check it.

mrfahadkhan
Posts: 27
Topic starter
(@mrfahadkhan)
Eminent Member
Joined: 3 years ago
1 Reply
Robert
Admin
(@robert)
Joined: 6 years ago

Support Team
Posts: 9373

@mrfahadkhan, please leave example of your embed URL not the post URL. What have you embedded in this page?

mrfahadkhan
Posts: 27
Topic starter
(@mrfahadkhan)
Eminent Member
Joined: 3 years ago

<iframe width="560" height="315" src="https://www.youtube.com/embed/WddvCQ6Bk0o" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

Sofy
Posts: 4057
 Sofy
Admin
(@sofy)
Support Team
Joined: 5 years ago

Hi @mrfahadkhan,

You just need to insert the URL without iframe tag, only the < https://www.youtube.com/embed/WddvCQ6Bk0o > part. 

By default, wpForo doesn't allow to use iframe tag, as it is not secure. There can be a lot of spam post.

In Dashboard > Forums > Tools > "Allow extra HTML tags" textarea you should add iframe tag name with its attributes . This will allow using iframe tag  (use the source ( {:} )  button before passing the link).

iframe
Page 1 / 2
Share: