Tagged: Facebook SDK for JavaScript
How can I add this snippet to my website.
Please see below JavaScript from Facebook.
The following snippet of code will give the basic version of the SDK where the options are set to their most common defaults.
You should insert it directly after the opening <body> tag on each page you want to load it:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : ‘XXXXXXXXXXXXXXX’,
xfbml : true,
version : ‘v2.3’
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = “//connect.facebook.net/en_US/sdk.js”;
fjs.parentNode.insertBefore(js, fjs);
}(document, ‘script’, ‘facebook-jssdk’));
</script>
Hey!
Try adding this at the very end of your theme / child theme functions.php file:
add_action('wp_footer', function() {
?>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : ‘XXXXXXXXXXXXXXX’,
xfbml : true,
version : ‘v2.3′
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = “//connect.facebook.net/en_US/sdk.js”;
fjs.parentNode.insertBefore(js, fjs);
}(document, ‘script’, ‘facebook-jssdk’));
</script>
<?php
});
Cheers!
Josue
Thanks, Josue.
I didn’t work. Please see the error message below.
Parse error: syntax error, unexpected ‘(‘, expecting T_STRING or T_VARIABLE or ‘$’ in /home/patrickp/public_html/iincomeplus.com.au/wp-content/themes/enfold-child/functions.php on line 19
I had to remove it from functions.php to be able to access my website again.
Kind regards,
Patrick
Hi Patrick,
Can you please create us a WordPress administrator account? post it here as a private reply.
Regards,
Josue