I’m having trouble getting results from wp_oembed_add_provider().
I’m developing a site which needs to embed video content from Facebook, and I came across this handy list of Facebook URL structures.
The one I’m focusing on to start with is #https?://(www\.)?facebook\.com/.*/videos/.*#i
as this matches the video I’m testing with.
Side point: This may or may not be an issue, but I don’t understand why the #
is there and the /
‘s are not escaped, as these practices usually would not be valid in a regex (according to my limited understanding of regexes). However, it does match the format of the YouTube example in the codex.
This is in my theme’s functions.php
:
add_action("init", function(){
wp_oembed_add_provider(
'#https?://(www\.)?facebook\.com/.*/videos/.*#i',
'https://www.facebook.com/plugins/video/oembed.json/',
true
);
});
The URL I’m attempting to match is: https://www.facebook.com/899lightfm/videos/972261526144646/
And the endpoint for Facebook seems to be correct, as https://www.facebook.com/plugins/video/oembed.json/?url=https://www.facebook.com/899lightfm/videos/972261526144646/ returns a valid response.
In a post, I have the video URL on its own line, followed by a similar YouTube URL on its own line. The YouTube URL is successfully detected and turned into an oembed – as one would expect, given WordPress supports it natively – but the Facebook URL does not get modified and instead is just printed out in plain text.
Am I using and hooking wp_oembed_add_provider()
correctly? Is there something else I should be doing so WordPress picks this up?
EDIT: I did try hooking into after_setup_theme
in case init
was too late, but am getting the same problem. Around the web init
seemed to be the more common action to hook wp_oembed_add_provider()
into.