How can I add Facebook SDK after

This topic contains 7 replies, has 2 voices, and was last updated by  Paolo 9 years, 1 month ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #35754

    Russell
    Expired Member
    Post count: 30

    Hi there,
    I want to add the Facebook SDK to my site just after the <body> tag. I am using Geo Framework Template and the latest version of WP Geo Directory and all plugins.

    Can you please help me with this?

    
    
    <div id="fb-root"></div>
    <script>(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_GB/sdk.js#xfbml=1&appId=1378194292506778&version=v2.3";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    #35765

    Paolo
    Site Admin
    Post count: 31206
    #35774

    Russell
    Expired Member
    Post count: 30

    Ok I am not 100% sure but I had a go using the following add action to my functions.php but get a syntax error in the first line.

    So here is the code snippet you mentioned on that post, would you be able to show me an example of how I would include the facebook sdk into it?

    
    
    add_action( 'geodir_details_main_content', 'facebook_sdk',35);
    
    function facebook_sdk(){echo 'hello world!';}

    Facebook Script

    
    
    <div id="fb-root"></div>
    <script>(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_GB/sdk.js#xfbml=1&appId=1378194292506778&version=v2.3";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    #35775

    Paolo
    Site Admin
    Post count: 31206

    What syntax error?

    this should work.

    Maybe try a more personalized function name…

    
    
    add_action( 'geodir_details_main_content', 'my_facebook_sdk',35);
    
    function my_facebook_sdk(){echo '<div id="fb-root"></div>
    <script>(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_GB/sdk.js#xfbml=1&appId=1378194292506778&version=v2.3";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>';}

    Let us know,

    thanks

    #35776

    Russell
    Expired Member
    Post count: 30

    I get
    Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in /home/media/public_html/pmg2015/wp-content/themes/GDF_child/functions.php on line 24

    I tried using a different function name (and the code snippet you posted) and got the same error.

    #35778

    Paolo
    Site Admin
    Post count: 31206

    ok, the best way to actually do this is to add the div facebook needs, via hook:

    
    
    
    add_action( 'geodir_details_main_content', 'my_custom_action',35);
    
    function my_custom_action(){ echo '<div id="fb-root"></div>'; }

    Than add the script part in GD >> design >> scripts >> footer script

    
    
    <script>(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_GB/sdk.js#xfbml=1&appId=1378194292506778&version=v2.3";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>

    Let us know,

    Thx

    #35779

    Russell
    Expired Member
    Post count: 30

    Perfect that works, thanks Paolo

    #35810

    Paolo
    Site Admin
    Post count: 31206

    Glad we solved ! 🙂

Viewing 8 posts - 1 through 8 (of 8 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket