This article will show you how to embed a Facebook post into your WordPress post or page with shortcode. Like a lot of Facebook embed features, it's arguably not the most efficient short-term means of displaying post content on your page. In fact, the default Facebook embed code that's provided in the menu attached to each post is quite adequate and will do as advertised.
So, Why Use Shortcode?
When the Facebook embed code changes (as it invariably will) - and assuming you were using the cheesy embed copy-and-paste embed code method - you would have to find and replace each occurrence of the embed code if you wish to use new features. With shortcode, of course, you only update one function and it effects changes site-wide. In fact, when we first published this code there were no available options for altering its behaviour in any way... and it's almost a guarantee that Facebook will introduce other features in the future.
Using the shortcode of
[fbpost url="https://www.facebook.com/beliefmedia/posts/1372047079556970"], we'll render the following Facebook post . Without providing a width, Facebook will scale the container automatically. We've applied the necessary code to center it.
The shortcode of
[fbpost url="10152007774068589" width="400"] will return the following (note that we've only provided the post ID, and we've also added a width of 400):
The ID-only method will only work on your own Facebook posts, or those posts belonging to to the
handle as defined by a shortcode attribute.
Where Do I Find the Post URL?
The post URL is found by copying the link on the post date. Right click on the date and select "Copy link address".
Copy and paste the WordPress function into your theme's
functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.
It's a requirement when using this function that you download the FBSDK function. Review its use and download the code here. It's possible that your theme is already rendering the SDK by default (open up your source code and search for "
connect.facebook.net" to confirm).
urlis either the full post URL or, if you have your
handledefined as your own page, just the post ID.
text="0"to exclude the text from the Facebook post, if any.
Outside of WordPress, the following can be used. The Facebook SDK is required.