0

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.net/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.com/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?

1 Answer 1

0

It 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.net/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?
3
  • I've used the above in my plugin. On the Chrome network tab, I can see 2 relevant events. One for the SDK load and another that loads some content (the first frame or two maybe?). In short, it looks like everything is working but the video player just isn't rendering properly.
    – lovelyzoo
    May 11, 2019 at 18:45
  • What do you see if you right click and view-source on the page? Can you see the fb-video HTML that you added to your post? May 11, 2019 at 19:40
  • Weirdly, the embedded videos page is now generating a new URL which embeds properly. Will mark this as correct since enqueueing seems more correct. Thanks.
    – lovelyzoo
    May 18, 2019 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.