If you plan on adding any kind of Facebook functionality to your website, such as like buttons, integrated videos, comments, or a page plugin, you will be required to add a snippet of JavaScript to each and every page you would like to see those features. While there's often an iframe option to accompany many of the features, the SDK option is almost always a better fit.
In the past, we always included the SDK JavaScript code with any of the code we shared, but this option meant that we were often providing snippets of code over and over again - often with minor variances. Providing a single source of the function will make it easier for us to share Facebook shortcodes for WordPress (and other PHP snippets) in the future.
While we've provided a WordPress plugin, it's almost always easier to simply add the code snippet to your functions.php
file (assuming you're using one).
The WordPress Function
Copy and paste the WordPress function into your theme's functions.php
file or, if you sensibly have one installed, your custom functions plugin.
While we can pass arguments to a function when using the add_action function (through do_action
), it's not appropriate with wp_head
(no arguments are called by
wp_head()
). While we can use apply_filters
to modify values, it's just easier to just define the values - which is what we've done (for $version
and $appid
).
PHP Function
Used outside of WordPress, the beliefmedia_fbsdk_head()
function should be used just after the opening body
tag.
Considerations
- It's quite possible your theme or another plugin is already rendering the Facebook SDK code. To check, view your website source code and look for "
connect.facebook.net
". If the code exists, it's highly likely the code already exists. - If you download the WP plugin, we'll notify you of updates via your dashboard.
Video Introduction
Download
The WordPress version intended for your functions.php
file is labeled as shortcode.
Title: Add The Facebook SDK To WordPress (WP Plugin)
Description: Add The Facebook SDK To WordPress. It is required for a number of other plugins and snippets.
Download • Version 0.2, 1.5K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (595.0B) PHP Code & Snippets, (589.0B)