Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1166430

    sk8trh8tr
    Participant

    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>
    #1166686

    Rahul
    Moderator

    Hey 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. 🙂

    #1166717

    sk8trh8tr
    Participant

    Hi,

    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

    #1167422

    Friech
    Moderator

    Hi 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.

    #1167628

    sk8trh8tr
    Participant

    Hi, I hadn’t closed the php block. So I tried that, adding the ?> before the <div

    Got 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

    #1167650

    sk8trh8tr
    Participant

    Hi,

    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.

    #1167718

    Darshana
    Moderator

    Glad you were able to figure it out 🙂