Tagged: x
-
AuthorPosts
-
September 8, 2016 at 9:09 am #1166430
Hello,
My site is http://www.backpacksandbridges.com
I wanted to use Facebook’s responsive like box . However the provided JS code blocks it to one language, so I found the code below, which replaces the language by current used language. The only change is the added PHP at the top to switch language. When I put it in my child theme’s functions.php, it generates an error though… Any idea why?
Thanks<div id="fb-root"></div> <?php $fb_lang = 'de_DE'; switch ( ICL_LANGUAGE_CODE ) { case 'en': $fb_lang = 'en_US'; break; case 'fr': $fb_lang = 'fr_FR'; break; }?> <script> // Load the SDK asynchronously (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.async=true; js.src = "//connect.facebook.net/<?php echo $fb_lang; ?>/ sdk.js#xfbml=1&version=v2.7"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script>
September 8, 2016 at 12:08 pm #1166686Hey There,
Thanks for writing in!
Instead of this, you could easily generate Facebook Like Box from the Facebook itself. The like box is already responsive so it plays nicely with a responsive theme as well.
You could use the Facebook like box generator https://developers.facebook.com/docs/plugins/page-plugin to get the like box code and insert it in a Text widget.
Hope that helps. 🙂
September 8, 2016 at 12:33 pm #1166717Hi,
Sorry, the problem is I need it to change the language in Facebook (ie the buttons etc.) By default the generator produces:
js.src = "//connect.facebook.net/en_US/ sdk.js#xfbml=1&version=v2.7";
this is why I need:
js.src = "//connect.facebook.net/<?php echo $fb_lang; ?>/ sdk.js#xfbml=1&version=v2.7";
And the Facebook generator also asks to insert JS code…
Unless there is another solution for this?Thanks
September 8, 2016 at 8:45 pm #1167422Hi There,
You wrote above: When I put it in my child theme’s functions.php, it generates an error though… Any idea why?.
Would you mind providing us the error code?
You have an HTML tag on top of your code
<div id="fb-root"></div>
that means you need to close [?>] the php block first, did you close your php block before you added the code?Please clarify, Thanks.
September 9, 2016 at 2:12 am #1167628Hi, I hadn’t closed the php block. So I tried that, adding the
?>
before the <divGot the same error message as before:
// ============================================================================= // Facebook multilingual like box // ============================================================================= Warning: Cannot modify header information - headers already sent by (output started at /home/backpa11/public_html/wp-content/themes/x-child/functions.php:148) in /home/backpa11/public_html/wp-includes/pluggable.php on line 1174
Thanks
September 9, 2016 at 2:40 am #1167650Hi,
So I put the code all the way at the top of the functions.php, before the first
<?php
.
Now the Facebook like box appears and is multilingual.
However it doesn’t quite seem responsive…But I think that’s a problem with Facebook itself, so you might be able to consider this solved.
September 9, 2016 at 3:38 am #1167718Glad you were able to figure it out 🙂
-
AuthorPosts