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.
The Result
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".
WordPress Shortcode
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.
If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.
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).
Shortcode Attributes
url
url
is either the full post URL or, if you have your handle
defined as your own page, just the post ID.width
text
text="0"
to exclude the text from the Facebook post, if any.handle
PHP Function
Outside of WordPress, the following can be used. The Facebook SDK is required.
Download
Title: Embed Facebook Posts into WordPress (WP Plugin)
Description: Display WordPress Meetups With a Shortcode or PHP Function. Renders WordPress meetups in a specific area. Results are cached for 24 hours.
Download • Version 0.3, 1.5K, zip, Category: WordPress Plugins (General)
WordPress Plugins (General), (712.0B) PHP Code & Snippets, (995.0B)