WordPress oEmbed Plus: Facebook and Instagram content embed

Published On12 Aug 2020

WordPress supports embedding external content such as Facebook videos, Instagram photos, YouTube videos, etc from the URL.

Facebook video being embeded in WordPress block editor The URL input is turned into an embeded Facebook video:

Embeded Facebook video

WordPress uses oEmbed

Internally, WordPress block editor uses oEmbed protocol and a legacy Facebook API to fetch post/photo/video/etc content and embed the HTML in the post.

Facebook deprecates legacy oEmbed API on 2020 October 24

The legacy API WordPress used to fetch embed contents did not require any credentials such as an access token to function, which made it possible to embed Facebook and Instagram content without any additional configuration.

Facebook is to deprecate the legacy oEmbed API on 2020 October 24.

Due to this change, WordPress 5.5.1 plans to remove Facebook and Instagram content embed support and hand over this functionality to a third party plugin.

Facebook and Instagram embeds with a plugin

The new self-plug WordPress plugin oEmbed Plus brings back the support for Facebook and Instagram oEmbed using Facebook's new API endpoints.

Once installed, this plugin needs to know a Facebook App access token to function. You can set the API key and secret in Admin Dashboard → Settings → Writing.

Admin page to enter Facebook API keys

Register a Facebook app

With a Facebook acccount and logged into it, head to Facebook Developer Apps list to create a new app. Click "Add a New App", and select "For Everything Else" for the use of it.

Embeded Facebook video You will need to enter a name for the app and an email. The app name can be any name. Name and email will not be shown in the WordPress front end at all.

Add oEmbed to the app

Once the app is created, you need to enable oEmbed feature for the app.

From the "Products" list, add oEmbed by clicking "Set Up".

Embeded Facebook video

Enter additional App details

In order to complete and retrieve API keys, the app needs to be live and complete.

The minimum requirement is setting a privacy policy. You can use pretty much any URL as the technical side is considered, but use a proper privacy policy if you have one.

Switch App to Live mode

Using the toggle on the top of the page that says "In Development", you can now switch the app to live mode.

You will be asked to enter additional details if anything is missing.

Get App ID and Secret and enter in plugin settings

To retrieve the App ID and Secret key, go to Settings → Basic in the Facebook app. You will see the App ID and Secret, which you can enter in the WordPress oEmbed Plus settings.

Embeded Facebook video

Set App ID and secret in settings file

As an alternative to setting the Facebook App ID and secret from the Administration settings page, it is also possible to set it in the wp-config.php file.

In a typical WordPress setup, the root wp-config.php file contains various settings for the site. Edit this file, and at the end of the file, set the Facebook App ID and secret by adding the snippet below:

define('OEMBED_PLUS_FACEBOOK_APP_ID', '<Enter App ID Here>');  
define('OEMBED_PLUS_FACEBOOK_SECRET', '<Enter Secret Here>');

Replace <Enter App ID Here> and <Enter Secret Here> fields with the real values. Make sure to remove the < > markers as well. For example, a configured value would look like this:

define('OEMBED_PLUS_FACEBOOK_APP_ID', '123...456');  
define('OEMBED_PLUS_FACEBOOK_SECRET', '123456abc...789def');

If configuration options are set in the wp-config.php file, the Administration dashboard form will be disabled, and wp-config.php file configuration will take precedence over Administration dashboard form settings.

That's it!

That's it. Your existing embedded content will continue to work (as they are stored as rendered HTML content). New Facebook and Instagram content will use the new authenticated API.

Rate limits

Facebook allows up to 5 million requests a day. Once the content is embeded, the output is cached in the database, and it does not trigger any further requests.

Contributions

Please check out the Git repository Ayesh/WordPress-oEmbed-Plus. PRs and issues are welcome!

Recent Articles on PHP.Watch

All ArticlesFeed 
PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

A guide for Debian and Ubuntu on how to install PHP 8.4 on a new server or how to upgrade an existing PHP setup to PHP 8.4.
How to fix `mysql_native_password` not loaded errors on MySQL 8.4

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to fix the SQLSTATE[HY000] [1524] Plugin 'mysql_native_password' is not loaded errors caused in MySQL 8.4 no longer enabling the mysql_native_password plugin by default.
How to fix PHP Curl HTTPS Certificate Authority issues on Windows

How to fix PHP Curl HTTPS Certificate Authority issues on Windows

On Windows, HTTPS requests made with the Curl extension can fail because Curl has no root certificate list to validate the server certificates. This article discusses the secure and effective solutions, and highlights bad advice that can leave PHP applications insecure.
Subscribe to PHP.Watch newsletter for monthly updates

You will receive an email on last Wednesday of every month and on major PHP releases with new articles related to PHP, upcoming changes, new features and what's changing in the language. No marketing emails, no selling of your contacts, no click-tracking, and one-click instant unsubscribe from any email you receive.

Support PHP.Watch — If you find the articles, version information, Codex, and other PHP.Watch contributions useful, consider supporting through GitHub Sponsors. Your sponsorship helps dedicate more time to creating valuable content and improving the PHP community. Together, we can keep the momentum going — thank you for your support!

Thanks to the highest tier sponsor: @TomasVotruba for your generous support to keep PHP.Watch moving 💜