I'm trying to embed a Facebook video in my site using the snippets generated by the Facebook Embedded videos page.
Having done so, I add this function to a custom, site specific plugin so as to load the FB javascript API:
add_action('wp_head', 'js_sdk_wp_head');
function js_sdk_wp_head(){
?>
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src=".js#xfbml=1&version=v3.3"></script>
<?php
}
I then use the code editor to add the following to the page:
<!-- wp:html /-->
<div class="fb-video" data-href="/?v=12345" data-width="500" data-show-text="false">
</div>
And when I do so, nothing happens, (apart from a blank line being inserted into the WP post).
What am I doing wrong?
I'm trying to embed a Facebook video in my site using the snippets generated by the Facebook Embedded videos page.
Having done so, I add this function to a custom, site specific plugin so as to load the FB javascript API:
add_action('wp_head', 'js_sdk_wp_head');
function js_sdk_wp_head(){
?>
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook/en_GB/sdk.js#xfbml=1&version=v3.3"></script>
<?php
}
I then use the code editor to add the following to the page:
<!-- wp:html /-->
<div class="fb-video" data-href="https://www.facebook/watch/?v=12345" data-width="500" data-show-text="false">
</div>
And when I do so, nothing happens, (apart from a blank line being inserted into the WP post).
What am I doing wrong?
Share Improve this question asked May 11, 2019 at 14:06 lovelyzoolovelyzoo 31 bronze badge1 Answer
Reset to default 0It worked correctly for me, however I used the wp_enqueue_scripts hook to add the JavaScript.
function mytheme_enqueue_scripts() {
wp_register_script('facebook-video', 'https://connect.facebook/en_GB/sdk.js#xfbml=1&version=v3.3', '', '');
wp_enqueue_script('facebook-video');
}
add_action('wp_enqueue_scripts', 'mytheme_enqueue_scripts');
- Do you see any errors in your browser console or network tab?
- Do you see the JS added to your page if you inspect?